Aborting DB operation

Aborting DB operation

Post by Chris L » Fri, 26 Aug 2005 22:49:12


Hi All,

I have a routine that loops through the rows of a large table. I want to
provide a mechanism for users to abort the operation any time. I tried
placing a button on the form with codes

procedure TfmForm1.Button1Click(Sender: TObject);
begin
Abort;
end;

But this cannot interrupt the loop. Can someone help?

Thanks.

Chris
 
 
 

Aborting DB operation

Post by Sonnic » Fri, 26 Aug 2005 23:02:30

No sure what you mean here, but it sounds are trying to do something
else than aborting an update.

Well, but if you e.g. have:

while not MyTable.EOF and not bButton1Pressed {boolean var} do
begin
// some action
MyTable.Next;
end;
Then you will use the bButton1Pressed to stop it.
If so, yuo might want to do so (depending on what database you are
using:

MyDatabase.StartTransaction;
while not MyTable.EOF and not bButton1Pressed {boolean var} do
begin
// some action
MyTable.Next;
end;
if bButton1Pressed then
MyDatabase.RollBack
else
MyDatabase.Commit;
The last part will cancel all changes done if the button is pressed in
this:

procedure TfmForm1.Button1Click(Sender: TObject);
begin
bButton1Pressed := True;
end;

 
 
 

Aborting DB operation

Post by Chris L » Fri, 26 Aug 2005 23:40:05


Hi sonnich,

I tried your suggestion. I'm not able to click on the Button1 when the loop
is executing. So that does not work. But it is exactly what I wanted to do,
and I'm not doing a transaction.

Chris
 
 
 

Aborting DB operation

Post by helmut woe » Sat, 27 Aug 2005 00:01:00

Am Thu, 25 Aug 2005 14:40:05 GMT schrieb Chris L.:




you have to tell the system it should check for new events:
...
while not MyTable.EOF and not bButton1Pressed {boolean var} do
begin
// some action
Application.ProcessMessages; // <---- this is the new line
MyTable.Next;
end;
...
This check will slow down the loop a little bit!

bye,
Helmut
 
 
 

Aborting DB operation

Post by dhr » Sat, 27 Aug 2005 01:09:13

On 25 Aug 2005 07:02:30 -0700, "Sonnich"


This will slow the operation somewhat but it works.



Applicaton.Prossessmesages;
 
 
 

Aborting DB operation

Post by Chris L » Sat, 27 Aug 2005 02:31:51

That works.
Thanks very much.
Chris




loop
do,