[Lazarus] Weird object variables access [SOLVED] - Delphi mode bug!
pascaldragon at googlemail.com
Tue Oct 24 17:04:37 CEST 2017
Am 24.10.2017 14:57 schrieb "Giuliano Colla via Lazarus" <
lazarus at lists.lazarus-ide.org>:
Il 24/10/2017 14:15, Mattias Gaertner via Lazarus ha scritto:
> On Tue, 24 Oct 2017 13:56:43 +0200
> Giuliano Colla via Lazarus <lazarus at lists.lazarus-ide.org> wrote:
>> Now the catch is that the queue used is just a queue of pointers, while
>> here we're dealing with procedures of object. This is legal with Delphi
>> syntax, while it is forbidden in ObjFpc.
> It's only legal with a typecast.
You can typecast a procedure of object to a pointer, but not the opposite.
And that is good.
> When I tried to see if the
>> problem was originated by Delphi mode, and changed to objfpc mode, it
>> turned out that there was no way to make it compile.
> The compiler tried to protect you from shooting yourself in the foot.
> Yes, but not in Delphi mode.
But just changing
>> my queue from a queue of pointers to a queue of TProc (TProc = procedure
>> of object) fixes the issue: it compiles, it works, Self is correct,
>> there's no need to qualify the identifier, and all is well.
>> The moral of the story is: in Delphi mode you can assign a procedure of
>> object to a pointer, and the compiler doesn't complain, but it is wrong,
> I just tried with $mode delphi:
> test1.pas(32,4) Error: Invalid assignment, procedures return no
But in Delphi mode
@NextProc := Coda.Remove;
Sending := True;
with NextProc defined as a procedure of object does compile but it's wrong.
Why are you using an @ when you assign the NextProc variable? O.o
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Lazarus