How to disable a Ttimer object when clicking a button that opens another form and re-enable it when the other form is closed?

Asked

Viewed 52 times

3

Good morning. I have a timer running on a form that calls several others. When this form opens another the timer should be stopped and when the form that was opened is closed the timer should be enabled again. However, I can only do this on one form. Is there any way to do that? Call the onclose of closed forms directly in the form that opens the others? I’m using Delphi 4.

I thought I’d put it this way, but I don’t know where I put that code so it runs at all times.

if Assigned(TForm1) then
  //Criado
else
  //Não criado

It would take another Ttimer object?

1 answer

3


The timer has the property Enabled, only mark as false and then back to true

and in the main form you invoke the second with showmodal, So the back form is on hold until the front one closes. stay can do so:

timer.enabled: false;

Form2:= TForm2.Create;
Form2.Showmodal;
freeanil(fomr2);

timer.enabled := true;
  • Thanks, Gabriel. I know that, I just don’t know where I put it. If I put on the button doesn’t answer, because I would have to put on all the onclose events of the other forms, you know?

  • i complemented the answer, with example code, but if you want to make the second form have control can give violated access problem, the better the form that has timer do the control. if you want to do in the main a generic process that opens the forms

  • 1

    It worked Gabriel. Thank you very much.

Browser other questions tagged

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