I always thought comparison of methods is done on both the data and the code part.
       TMethod = record
         Code : CodePointer;
         Data : Pointer;
       end;
But the following proves it is NOT.
What is the rationale behind such behavior?

--------------
program compare_events;
{$mode objfpc}{$H+}
uses classes;
type

  TA=class
    procedure Proc(aSender : TObject);virtual;
  end;

  TB=class(TA)
    procedure Proc(aSender : TObject);override;
  end;

  TC=Class(TA)
  end;

var
  E1,E2,E3 : TNotifyEvent;
  A : TA;
  B : TB;
  C : TC;
procedure TB.Proc(aSender: TObject);
begin
  inherited Proc(aSender);
end;

procedure TA.Proc(aSender: TObject);
begin

end;

begin
  a := TA.Create;
  B := TB.Create;
  C := TC.Create;
  try
    E1 := @(A.Proc);
    E2 := @(B.Proc);
    E3 := @(C.Proc);
    if E1 = E2 then
      Writeln('A.Proc = B.Proc')
    else
      Writeln('A.Proc <> B.Proc');

    if E1 = E3 then
      Writeln('A.Proc = C.Proc')
    else
      Writeln('A.Proc <> C.Proc') ;

    Readln;
  finally
    A.Free;
    B.Free;
    C.Free;
  end;
end.

{===============the program gives the following output}

A.Proc <> B.Proc
A.Proc = C.Proc
{end of output}





_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to