[Lazarus] Newbie, porting class to FPC but get procedure assignment error

Santiago Amposta svaa at ciberpiula.net
Wed Jun 24 13:02:37 CEST 2015


El 19/06/2015 a las 9:38, Luca Olivetti escribió:
> El 19/06/15 a les 09:25, Bo Berglund ha escrit:
>
>> constructor TSentinel.Create;
>> begin
>>    FTimer := TTimer.Create(Application);
>>    FTimer.Enabled := false;
>>    FTimer.Interval := 0;
>>    FTimer.OnTimer := OnCheckTimer(Self); //<= Error here
>>    ...
>
>>
>> Why is this difference Delphi/FPC appearing and what can I do?
>>
>
> Either you use {$MODE DELPHI} or you prepend the method with @, i.e.
>
> FTimer.OnTimer := @OnCheckTimer
>
I think that Luca's code doesn't work on delphi either.
He should write
 FTimer.OnTimer := OnCheckTimer;
Without the self parameter "self".

If you add the parameter self, delphi would think you call method
function called OnChecktimer. As OnCheckTimer is a procedure, not a
function, rises error.

If OnTimer wouldn't had parameters, there could a confusion, that IMHO
FPC with @ solves in an elegant way. With a parameter there is no
ambiguity, that's an error: Assigning to variable the result of procedure.


-- 
Santiago A.





More information about the Lazarus mailing list