Solved

testing for an empty dataset before deleting a record

Posted on 1998-09-30
1
1,247 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Delphi 2010 Export to pdf 2 253
How can I open IE in olecontainer? 7 109
Delphi TcxGrid group footer summary 3 149
Delphi selector screen 2 58
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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

746 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

13 Experts available now in Live!

Get 1:1 Help Now