Run commands when opening program

Asked

Viewed 1,222 times

2

Well, I am trying to execute several commands when opening the program, but this prevents the same to be shown at the desired time, since it executes all to then show. I am trying to execute such commands in the form Onshow. Since you have a For, it takes a long time to open. Is there any way to delay the time the program is shown and the commands? Causing all to run after the program is shown?

1 answer

2


You can use the component TTimer.

  1. Add it to the form;

  2. seven your property Enable for false.

  3. Enter a relative time for the form to be displayed, approximately 2 seconds = 2000 thousandths in the property Interval;

    The default value of this property is 1000 (1000 thousandths of a second = 1 second). Changing to 2000 will be two seconds.

  4. In the last line of the method OnShow of the form, seven property Enable for true:

    Example:

    timer1.Enable := true;
    
  5. Now you need to pass your commands to the event OnTimer of the component TTimer. To do this, double-click on the component that will then be created the default method OnTimer.

  6. Change your commands that are on OnShow form for that new method created.

Ready!
After the given time, such as 2 seconds, the commands will start to be executed.


Details about the component TTimer:

The component TTimer has an event called OnTimer which is the main resource of that component and is what has been described in that response to be used.

But, the component TTimer does not perform this method only once, but rather indeterminate times, from time to time, at intervals defined by the time value set in its property Interval.

Therefore, to have the method run only once you need to disable it right when running for the first time, thus:

// assinatura fictícia do método / exemplo
procedure FormFicticio.Timer1OnTimer(Sender: TObject);
begin
  Timer1.Enable := false;  // <-- isso deve ser feito

  // Os demais comandos que deseja executar
end;

Doing this he will run only once.
Otherwise it will always execute, as already mentioned.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.