Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2016-07

Surprise. Comparison of method is only done on the routine address

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Dennis

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}

Michael Van Canneyt
to Dennis
Dennis wrote 8 lines
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?

AFAIK: Delphi compatibility.

Someone already made a remark about this, and this fact is now documented, it should appear when 3.0.2 is out.

Michael.

Dennis Poon
to Michael Van Canneyt
Michael Van Canneyt wrote 15 lines
On Tue, 12 Jul 2016, Dennis wrote: > 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? AFAIK: Delphi compatibility.

May I know what do they claim to be the rationale behind this decision?

Dennis

Michael Van Canneyt
to Dennis Poon
Dennis Poon wrote 19 lines
Michael Van Canneyt wrote: > > > On Tue, 12 Jul 2016, Dennis wrote: > >> 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? > > AFAIK: Delphi compatibility. > May I know what do they claim to be the rationale behind this decision?

I have no idea, I am curious myself.

Michael.