[fpc-devel] comparing methods
Mattias Gärtner
nc-gaertnma at netcologne.de
Thu Sep 10 15:18:38 CEST 2009
Zitat von Thaddy <thaddy at thaddy.com>:
> 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.
Not at all. But thanks for trying.
> 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.
The 'a,b' above are pointers to mem areas. a=b compares the pointers.
If a,b would be records then a=b would compare the mem.
If a,b would be 'procedure of object' then a=b compares only half of
the mem. This is different to both cases above.
Hope this helps.
Mattias
More information about the fpc-devel
mailing list