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

Michael Van Canneyt michael at freepascal.org
Tue Oct 24 14:10:49 CEST 2017

On Tue, 24 Oct 2017, Giuliano Colla via Lazarus wrote:

> Il 23/10/2017 22:57, Mattias Gaertner via Lazarus ha scritto:
>> Check if 'Self' inside SendMessage is the right instance.
> 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, 
> because when you call your method through this pointer, the method is 
> executed, but it's unaware of the data space of the object it belongs 
> to, even if it's called from another method of the same object! If the 
> method doesn't access variables of the object, everything appears to 
> work, but if it does the program simply crashes.
> I will try to see if the same occurs also in Delphi, to understand if 
> it's a Delphi bug or an fpc bug.

A valid method can never be stored in a pointer, since the former is actually 
2 pointers (method/data) and the latter is just 1 pointer.

That the assignment is valid is Delphi compatible: only the procedure
address is copied.


More information about the Lazarus mailing list