[fpc-devel] comparing methods

Thaddy thaddy at thaddy.com
Thu Sep 10 13:59:43 CEST 2009


Mattias Gärtner wrote:
> Hi,
>
> Can someone explain why in mode objfpc comparing methods only compares 
> the address, but not the instance?
> For example:
>
>   a:=TMyClass.Create;
>   b:=TMyClass.Create;
>   if @a.test = @b.test then writeln('the same method');
>
> This results in strange behaviors, when using the following code (from 
> the FCL):
>
> property AfterConnect: TNotifyEvent read FAfterConnect write 
> SetAfterConnect;
>
> procedure TCustomConnection.SetAfterConnect(const AValue: TNotifyEvent);
> begin
>   if FAfterConnect=AValue then exit;
>   FAfterConnect:=AValue;
> end;
>
>
> Mattias
>
>
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
>
The deep copy versus shallow copy problem.
Depending on what you want. here it is implementing a deep compare, (an 
instance full copy) instead of a shallow compare (a pointer copy). Both 
are valid paradigms, but also -very, very - basic computer science. You 
for some reason want a shallow compare, which may or may not be correct, 
depending on your code.



More information about the fpc-devel mailing list