hi, Bandit :)
there are at least two ways to achieve what you need - repeatedly call Application.ProcessMessage
wbr, mo.
Main Topics
Browse All TopicsThis should be simple... But I cannot get it to work.
This is in Delphi 7 - I've got 2 units, unit1 & unit2 with form1 and form2. Form1 has a single button 'Start'. Form2 has a progress bar and a button 'Cancel'.
Unit1.pas
procedure TForm1.StartClick(Sender: TObject);
var
i : integer;
begin
Form2.Show;
for i := 1 to 1000000 do
begin
Form2.ProgressBar1.Positio
Form2.Update;
end;
end;
Unit2.pas
procedure TForm2.CancelClick(Sender:
begin
Form2.Close;
end;
This is a very simplified example of what I have in my application - on running, Form1 shows - the Start button is clicked which starts a lengthy routine where I need to show the progress - so I show Form2 with a progress bar. What I want to do is be able to give the users the option of cancelling the routine by clicking on the cancel button on Form2. Trouble is that despite Form2 having focus it receives no events - specifically the CancelClick event never gets activated and so I can never escape from the routine.
How do I impliment this correctly? Thanks.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Check this:
http://delphi.about.com/gi
It might be of help...
Business Accounts
Answer for Membership
by: BJThomsenPosted on 2004-04-13 at 12:42:00ID: 10816749
You need you application to ProcessMessages during your long process.
: TObject); n := Form2.ProgressBar1.Positio n + 1; s;
: TObject);
;
;
);
n; n := Form2.ProgressBar1.Positio n + 1;
---------- -----
: TObject);
e := True;
---------- ---------- -----
: TObject);
procedure TForm1.Button1Click(Sender
var
i: integer;
begin
Form2.Show;
Form2.Canceled := False;
for i := 1 to 1000000 do
begin
if Form2.Canceled then
Exit;
Form2.ProgressBar1.Positio
Form2.Update;
Application.ProcessMessage
end;
procedure TForm2.Button1Click(Sender
begin
Canceled := True;
Form2.Close;
end;
Another way to do this would be to put your long process in an actual thread. Like so:
unit Unit3;
interface
uses
Classes;
type
TLongProcess = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
procedure UpdatePosition;
end;
implementation
{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example,
Synchronize(UpdateCaption)
and UpdateCaption could look like,
procedure TLongProcess.UpdateCaption
begin
Form1.Caption := 'Updated in a thread';
end; }
{ TLongProcess }
uses Unit2;
procedure TLongProcess.Execute;
var
i: Integer;
begin
for i := 1 to 1000000 do
begin
if Terminated then
Exit;
Synchronize(UpdatePosition
end;
end;
procedure TLongProcess.UpdatePositio
begin
Form2.ProgressBar1.Positio
Form2.Update;
end;
end.
--------------------------
procedure TForm2.Button1Click(Sender
begin
LongProcess.Terminate;
Form2.Close;
end;
procedure TForm2.FormShow(Sender: TObject);
begin
LongProcess := TLongProcess.Create(True);
LongProcess.FreeOnTerminat
LongProcess.Resume;
end;
--------------------------
procedure TForm1.Button1Click(Sender
begin
Form2.Show;
end;