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

Sven Barth pascaldragon at googlemail.com
Wed Oct 25 14:20:46 CEST 2017


Am 25.10.2017 14:12 schrieb "Giuliano Colla via Lazarus" <
lazarus at lists.lazarus-ide.org>:

Il 25/10/2017 13:41, Mattias Gaertner via Lazarus ha scritto:

No. The Delphi syntax is "ProcIdentifier:=Proc" or
"ProcIdentifier:=@Proc".

The "@Some:=" means assign something to address of Some. Which is bogus.
I guess Delphi's auto dereference actually translates this to
@Some^:=. Still bogus, but valid bogus.

>From embarcadero doc wiki (http://docwiki.embarcadero.
com/RADStudio/Tokyo/en/Procedural_Types_(Delphi)):

Procedural Types in Statements and Expressions

When a procedural variable is on the left side of an assignment statement,
the compiler expects a procedural value on the right. The assignment makes
the variable on the left a pointer to the function or procedure indicated
on the right. In other contexts, however, using a procedural variable
results in a call to the referenced procedure or function. You can even use
a procedural variable to pass parameters:

[snip]

The *@* operator can also be used to assign an untyped pointer value to a
procedural variable. For example:

 var StrComp: function(Str1, Str2: PChar): Integer;
    ...
 @StrComp := GetProcAddress(KernelHandle, 'lstrcmpi');


This  is no more true (as least as of X10 where I tested and it gave rise
to a compiler error), but it has been for a long time. That's why I assumed
that assigning an untyped pointer to a procedural variable was both legal
and also properly supported.


Did you test with a procedure pointer type or a method pointer type? Cause
this might be the important difference here as the example uses a procedure
pointer type.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20171025/0229ce57/attachment-0001.html>


More information about the Lazarus mailing list