Solved

testing for an empty dataset before deleting a record

Posted on 1998-09-30
1
1,254 Views
Last Modified: 2006-11-17
How can i test if the dataset is empty before allowing an button click event to delete a record?

If it is empty i want to respond with an appropriate dialog box, but i can't figure out an effective way to check first that it doesn't happen to be empty

any clues?
0
Comment
Question by:npepper
1 Comment
 

Accepted Solution

by:
dejohn99 earned 50 total points
ID: 1341295
Either of these should work.

Wherever I have used DataSet1.Delete, you should put your normal Delete processing, whatever it may be.

procedure btnDelete1Click (Sender: TComponent)
begin
    if DataSet1.RecordCount = 0 then
        raise Exception.Create ('Dataset '+DataSet1.Name+' is empty');

    DataSet1.Delete;
end;



procedure btnDelete2Click (Sender: TComponent)
begin
    if DataSet1.RecordCount = 0 then
        MessageDlg ('Dataset '+DataSet1.Name+' is empty',
            mtError, [ mbCancel ], 0);
    else
        DataSet1.Delete;
end;


If you are concerned that the RecordCount may not be kept current, you might try this:

procedure btnDelete3Click (Sender: TComponent)
begin
        { EOF and BOF will only both be true for an empty dataset }
        if DataSet1.EOF and DataSet1.BOF then
            MessageDlg ('Dataset '+DataSet1.Name+' is empty',
                mtError, [ mbCancel ], 0)
        else
            DataSet1.Delete;
end;


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
indy tidtcpclient threading issue 8 63
Delphi XE10, MySQL Query 4 126
Best Firemonkey component pack 1 86
Need Help Delphi 2010 CheckBox1 Stored value in memo 13 56
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now