Re: timing program with Delphi?

Posted by Jenny on May 25, 2005

In Reply to: How can do timing program? posted by zmo on May 15, 2005

: I want to know, how can timing program. I want to do the following: at first i want to give measure time (eg. 45 min,...), it must be display in other text box. When the time's finish (when giving measure time = display time), it must be stop.

If you want to stop the program after a certain time, it's best to use a TTimer component, that checks if the time has elapsed, for example every second.

Drop a Timer component on the main form, say Timer1, set its property Enabled to False, and set Interval to 1000. Create an OnTimer event:

procedure TForm1.Timer1Timer(Sender: TObject);
  if Time >= TimeToStop then Close;

Drop a TEdit component on the form, to enter the delay time (waiting time) in seconds. Set its property Text to 1.

Drop a Button on the form, and make an OnClick event handler like this:

procedure TForm1.Button1Click(Sender: TObject);
  TimeToStop := Time + StrToInt(Edit1.Text)/(3600*24);
  Timer1.Enabled := True;

Finally, add a global variable:

TimeToStop: real; 

Good luck!

Related Articles and Replies





[ Delphi Tutorials -- by DelphiLand ]