Does anybody know how this must be done?
Thanks for any help,
Andreas Seebeck
The timer event expects an *object* procedure.
So make the procedure into a method on your form, like this:
procedure TForm1.OnTimerProc(Sender: TObject);
Then you can write
mytimer.OnTimer := OnTimerProc;
Finn Tolderlund
Look at the declaration of TNotifyEvent: it is <procedure ... of object>, so
you will need to create a method in stead of a stand alone procedure:
procedure MyObject.OnTimerProc(Sender: TObject);
Guido GYBELS
Programmer (GDG GROEP BELGIUM)
Andreas Seebeck <A...@febe.com> schrieb im Beitrag
<8uejq9$5k...@bornews.inprise.com>...
> Hi,
> just wanted to create a TTimer at runtime but ran into the problem that I
> cannot simply write a procedure ontimerproc(sender: TObject); and assign
it
> to the ontimer event like mytimer.ontimer:=ontimerproc;
>
> Does anybody know how this must be done?
>
You can, but the procedure has to be a method of some object, e.g. the form.
Methods have an additional hidden parameter (Self), so they are not
compatible with a standalone procedure that seem to have the same parameter
list.
Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
One should really declare the procedure as method of some object. However,
if that is not possible the following work around exists.
procedure HandleTick (Sender : tObject); forward;
const HandleTickHack : tMethod = (code : @HandleTick; data : nil);
. . .
myTimer.OnTimer := tNotifyEvent (HandleTickHack);
Its not really necessary to use a forward declaration but IMO it makes
things a bit clearer.
I tried this, so now it IS a method of some object. Here is the decl.:
type TIAni = class(TRBob)
procedure onTimerproc(Sender: TObject);
protected
private
public
end;
but mytimer.ontimer:=TIAni.ontimerproc; gives me the comp. error
[Error] Unit1.pas(164): Incompatible Types: 'TNotifyEvent' and 'Procedure'
Any hints?
Thank you very much for all the help!
best regards,
Andreas Seebeck
>
> Peter Below (TeamB) 10011...@compuserve.com)
> No e-mail responses, please, unless explicitly requested!
>
I'm very sorry, I hit the wrong button.
Without more code, I can only guess, but you obviously are doing something
wrong, probably while declaring the procedure. Let's assume you have a form
TForm1 and a timer, Timer1. Declare a method for the form by adding a line
to the private declarations of the form:
procedure MyEventProc(Sender: TObject);
Afterwards, you can simply assign this procedure to the OnTimer event:
Timer1.OnTimer:=MyEventProc;
Hope this helps,
I had exactly the same problem some time ago and managed to solve it using a
"Class Method" inside a dummy class. "Class methods" don't require you to
instantiate the object defined by the dummy class before calling them.
Instead (I believe), you simply call a class method with a class prefix.
So, instead of OnClick := Click;
you would write OnClick := TDummyClass.Click;
I'd love to show you an exact example, but it's on my system at home. Try
looking up Class Methods in the Delphi help. Maybe someone else here can
explain this approach better than I can.
Best of luck
Regards
Stan Stern.
Well, i said "method of an object", you are trying to use the *class* itself
here, not an instance of it (a object). The error message is somewhat
misleading, unfortunately.
Var
aTIAni: TIAni;
aTIAni := TIAni.Create;
mytimer.OnTimer := aTIAni.OnTimerproc;
The aTIAni object has to live at least as long as the timer object is tied
to its method.