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.

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.
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to