[Lazarus] Weird object variables access [SOLVED] - Delphi mode bug!
lazarus at kluug.net
Wed Oct 25 10:49:31 CEST 2017
On 24.10.2017 23:18, Michael Van Canneyt via Lazarus wrote:
> On Tue, 24 Oct 2017, Giuliano Colla wrote:
>> Il 24/10/2017 14:10, Michael Van Canneyt via Lazarus ha scritto:
>>> 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.
>> I can confirm it as an fpc bug.
> No, I'm sorry to say that IMO you did not. I looked at your code.
> It simply works by accident in Delphi, because you are calling a
> method of the same object as the caller.
Yes, the code is wrong. But the reason is that myMethod is assigned in
FormCreate. The later "@myMethod := pMethod;" assignment overwrites only
half of the myMethod:TProc variable and so correct Self stays in the
second half of myMethod.
Remove FormCreate and you get an AV.
Furthermore, "Format('0x%P',[@Myself])" doesn't make sense - it should
No bug at all - just wrong code.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Lazarus