Recent

Author Topic: Dialog can't use Timer  (Read 3554 times)

new_one

  • New Member
  • *
  • Posts: 20
Dialog can't use Timer
« on: November 20, 2010, 11:46:24 am »
Hello,
I have one question about dialogs. I'm working on project to school and I'd used dialog to show with question "Do you want to repeat?" and buttons "yes" and "no". I have done this
Quote
Procedure DisplayMessageBox;
 var reply, boxstyle: integer;
 begin
   with application do begin
     boxstyle :=  MB_ICONQUESTION + MB_YESNO;
     reply :=  MessageBox ('Do you want to repeat?', 'MessageBoxDemo', boxstyle);
     if reply = IDYES then
       begin
         X:= 0;
         Timer1.Enabled:= True; // This line causing error Identifier not found
       end
     else MessageBox ('No         ', 'Reply', MB_ICONHAND);
 end;
end;
Timer1.Enabled:= True; // This line causing error "Identifier not found". I can use Timer1 in every procedure, function...but not there? How Can I enable Timer1?

Thanks

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Dialog can't use Timer
« Reply #1 on: November 20, 2010, 12:06:08 pm »
You need to declare your procedure as a method of your Form to access a timer of that class:

Code: [Select]
private
    { private declarations }
Procedure DisplayMessageBox;

(...)

Procedure TYourForm.DisplayMessageBox;
begin
// your code
end;

« Last Edit: November 20, 2010, 12:08:46 pm by typo »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9877
  • Debugger - SynEdit - and more
    • wiki
Re: Dialog can't use Timer
« Reply #2 on: November 20, 2010, 12:09:08 pm »
your procedure is not part of the class Form1.

either:

1) write in the declaration of Form1 (or whatever name your form is)
Code: [Select]
Form1=Class(TForm)
...
  protected
    Procedure DisplayMessageBox;


and then
Procedure TForm1.DisplayMessageBox;

That way the procedure knows all the things that are part of the Form (like the timer)


2)
write
  Form1.Timer1.Enabled

but that's less good, as you access Form1 => a global variable....  => and global variables should be avoided

new_one

  • New Member
  • *
  • Posts: 20
Re: Dialog can't use Timer
« Reply #3 on: November 20, 2010, 12:11:23 pm »
Thanks it runs goos now

 

TinyPortal © 2005-2018