[Lazarus] Weird object variables access [SOLVED] - Delphi mode bug!

Mattias Gaertner nc-gaertnma at netcologne.de
Tue Oct 24 14:15:49 CEST 2017


On Tue, 24 Oct 2017 13:56:43 +0200
Giuliano Colla via Lazarus <lazarus at lists.lazarus-ide.org> wrote:

>[...]
> Yes, you're right, that's what clarifies the issue. When it works, Self 
> is a TFORM1 object, when it fails, Self is just Nil.
> 
> But now it's also clear why this happens.

I'm glad you figured it out.

>[...]
> 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.


> 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.


> 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:

p:=o.DoIt;

test1.pas(32,4) Error: Invalid assignment, procedures return no
value

Mattias


More information about the Lazarus mailing list