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

Giuliano Colla giuliano.colla at fastwebnet.it
Wed Oct 25 13:05:57 CEST 2017


Il 24/10/2017 23:18, Michael Van Canneyt via Lazarus ha scritto:
> It simply works by accident in Delphi, because you are calling a 
> method of the same object as the caller. Try calling a method of 
> another object, and displaying the classname and make sure you trash 
> the registers between the assignment
> of the method pointer and actually calling it. 

I'm forced to admit that you're (almost) right.

Changing the initial assignment of myMethod from a valid procedural type 
to Nil, makes theĀ  program crash in Kylix.

I found it hard to swallow that Delphi of the good old times allowed 
such an unsafe assignment without even a warning, and I had assumed that 
they were using some compiler magic to work around the issue, but 
apparently this is the sad truth.

However some issues remain, about fpc Delphi mode:

With older Delphi's up to, I believe, Delphi 7 you have that:

1) the syntax for the assignment of a procedural type is @ProcIdentifier 
:= whatever;

2) If whatever is a pointer, and ProcIdentifier is a Method, the data 
field is left untouched

This made it possible, with some dirty tricks to build a proper method 
procedural type.

In recent Delphi's (someone tested with X7, I did with X10)

1) The syntax @ProcIdentifier := whatever is no more valid. It's no more 
possible to assign a pointer to a method type without typecasting.

2) Assigning (with typecasting) a pointer to a method type will set the 
data field to Nil.

This makes it impossible to use dirty tricks.

Currently fpc in Delphi mode accepts the old syntax, but sets the data 
field to Nil, thus creating a misleading inconsistency.

Giuliano




More information about the Lazarus mailing list