Zitat von Thaddy <tha...@thaddy.com>:

Mattias Gärtner wrote:
Zitat von Michael Schnell <mschn...@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

_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to