Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

start/stop at runtime 2

Status
Not open for further replies.

nyilas

Technical User
Apr 29, 2002
1
DE
Hi,
A simple problem to be solved using Delphi OOP:
A button counts an integer

procedure TForm1.Button1Click(Sender: TObject);
var
i :int64;
begin
i:=0;
(While not (i=10000000) do begin
inc(i);
if ??????????
end;
showmessage(IntToStr(i));
end;

I need a way to stop and start the counting action at the runtime.
I will appreciate if you know a way to solve this problem.
Thanks
Arman
email : arman.nyilas@itp.fzk.de
 
You could use a TTimer and put your IF statement in the TTimer.OnTimer event. Then enable/disable the timer as required.

Also wise to put plenty of Application.ProcessMessages in your code when using Timers.
 
Code:
stopCounting := False;

While (i < 10000000) and (not stopCounting) do 
begin
   inc(i); 
   Application.ProcessMessages;
end;
Set stopCounting to True in whatever event handler/procedure you want to use to stop the count.
 
Looping structures
The most important part of Mikes example is the line application.processmessages;
If you dont include this in an indeterminate loop e.g a while or repeat/until, then your programm can get stuck in the loop and the only way out will be a reset button press.
This line forces your program to give way to windows keyboard and mouse scans, so you can (should be able to)stop it from the Delphi Menus.

Steve.
 
take a variable,
assign the user input to the variable
use the variable instead of the number in yr code
hope it will help
cheers,
Asim.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top