Board index » delphi » problem deleting records with eof etc....

problem deleting records with eof etc....

Can someone put me right here ???

the following code scans 28000 records, putting the record numbers deleted
in a memo

No message is generated but only a small % of records actualy get deleted!

I had to run it about 5 times!!!!!

procedure TForm1.Button1Click(Sender: TObject);
begin
with dm.tbljcitems do begin  file://dm is the datamodule
 first;
 while not eof do
     begin
       if fieldbyname('jobno').value < 5000 then
           begin
            memo1.lines.add('Del '+ inttostr(dm.tbljcitemsjobno.value));
           try
            edit;
            delete;
             except
              showmessage('OH Dear OH Dear a problem');
           end; end;
           next;
           end; end;   end;

 

Re:problem deleting records with eof etc....


Oh by the way,  Im using paradox 7 tables BDE

Re:problem deleting records with eof etc....


On Fri, 21 Jan 2000 16:27:50 -0000, "Les Haagensen"

Quote
<les.haagen...@talk21.com> wrote:
>No message is generated but only a small % of records actualy get deleted!

>I had to run it about 5 times!!!!!

>procedure TForm1.Button1Click(Sender: TObject);
>begin
>with dm.tbljcitems do begin  file://dm is the datamodule
> first;
> while not eof do
>     begin
>       if fieldbyname('jobno').value < 5000 then
>           begin
>            memo1.lines.add('Del '+ inttostr(dm.tbljcitemsjobno.value));
>           try

// Remove this line
//            edit;  
Quote
>            delete;
>             except
>              showmessage('OH Dear OH Dear a problem');

           end;
// Delete already skips the deleted record
         end else
         begin
            next;
         end;

Quote
>           end; end;   end;

HTH,

Jan

Re:problem deleting records with eof etc....


D. Widjaja   Thanks for your prompt reply.
I wil try it.

Re:problem deleting records with eof etc....


On Fri, 21 Jan 2000 16:27:50 -0000, "Les Haagensen"

Quote
<les.haagen...@talk21.com> wrote:
>Can someone put me right here ???

>the following code scans 28000 records, putting the record numbers deleted
>in a memo

>No message is generated but only a small % of records actualy get deleted!

>I had to run it about 5 times!!!!!

>procedure TForm1.Button1Click(Sender: TObject);
>begin
>with dm.tbljcitems do begin  file://dm is the datamodule
> first;
> while not eof do
>     begin
>       if fieldbyname('jobno').value < 5000 then
>           begin
>            memo1.lines.add('Del '+ inttostr(dm.tbljcitemsjobno.value));
>           try
>            edit;
>            delete;
>             except
>              showmessage('OH Dear OH Dear a problem');
>           end; end;
>           next;
>           end; end;   end;

When you delete a record, the next record automatically becomer the current
record. But if you call the Next method, you advance the record pointer
beyond that new current record. IOW, you would only be deleting every other
record.

Another thing is that you do not need to call the Edit method prior to
calling Delete.

==========================================================================
Steve Koterski                  "Computers are useless. They can only give
Technical Publications          you answers."
Borland                                       -- Pablo Picasso (1881-1973)
http://www.borland.com/techpubs/delphi

Re:problem deleting records with eof etc....


Once current record is deleted, the pointer will move to the next record.
After the deletion, try not to move to next record.
Quote
Les Haagensen wrote in message <86a112$i...@bornews.borland.com>...
>Can someone put me right here ???

>the following code scans 28000 records, putting the record numbers deleted
>in a memo

>No message is generated but only a small % of records actualy get deleted!

>I had to run it about 5 times!!!!!

>procedure TForm1.Button1Click(Sender: TObject);
>begin
>with dm.tbljcitems do begin  file://dm is the datamodule
> first;
> while not eof do
>     begin
>       if fieldbyname('jobno').value < 5000 then
>           begin
>            memo1.lines.add('Del '+ inttostr(dm.tbljcitemsjobno.value));
>           try
>            edit;
>            delete;
>             except
>              showmessage('OH Dear OH Dear a problem');
>           end; end;
>           next;
>           end; end;   end;

Other Threads