Programmatically Creating TTimer; OnTimer issue. [resolved]
lazarus / 8-Other
----------------------------------------------------------------------
daz · 2009-07-14 06:47
So I've basically done in another unit with no form:
Code: [Select]procedure onFade(Sender: TObject);
begin
end;
Code: [Select]fadetimer := TTimer.Create(nil);
fadetimer.Enabled := true;
fadetimer.Interval := 5000;
fadetimer.OnTimer := @onFade;
And it yells at me.
Error message:
unit1.pas(51,34) Error: Incompatible type for arg no. 1: Got "
", expected ""
Since I've had problems with using a pointer before; I tried making
the mode delphi and still got an error:
unit1.pas(52,34) Error: Incompatible type for arg no. 1: Got
"Pointer", expected ""
A solution for either delphi mode or objfpc mode would be very
graciously accepted.
----------------------------------------------------------------------
Vincent Snijders · 2009-07-14 07:23
OnFade must be a method of an object, not a plain procedure.
----------------------------------------------------------------------
Leledumbo · 2009-07-14 07:28
Compiler mode isn't the problem, but onFade declaration is. It's a
pure procedure while OnTimer expects method, which is called procedure
of object in the compiler's terminology.
Solution:
Declare it as part of a class (the form maybe?).
----------------------------------------------------------------------
daz · 2009-07-14 15:12
Quote from: Leledumbo on July 14, 2009, 09:28:43 amSolution:
Declare it as part of a class (the form maybe?).
This; and some other scrap on the internet about it having a
NotifyEvent helped me understand how it works the most. I've got it
working now.