[fpc-devel] comparing methods

Thaddy thaddy at thaddy.com
Thu Sep 10 14:09:49 CEST 2009


Mattias Gärtner wrote:
> Zitat von Michael Schnell <mschnell at lumino.de>:
>
>> Mattias Gärtner wrote:
>>> Can someone explain why in mode objfpc comparing methods only compares
>>> the address, but not the instance?
>>
>> Seems perfectly logical to me (@ = Address of, in this case "code
>> address", the code is the same for all instances of a class).
>
> OnClick:=@MyClick;
>
> The @ operator is more than "address of".
>
Nope, it is: although there is some vmt work involved : the data part is 
for the new instance, not the global instance. Assigning a new method to 
one of the two instances your example gives makes them unequal because 
the instances are deep copies or rather new instances of the same class 
with different addresses. Hopes that helps.

If you assign to an empty variable, like

var a,b:TMyClass;
begin
b:= TMyClass.Create;
a:=b;
end;

You will get the result you expect.

Again, very basic.



More information about the fpc-devel mailing list