Einzelnen Beitrag anzeigen

mse1

Registriert seit: 21. Nov 2007
115 Beiträge
 
#10

AW: Prüfen, ob eine Method überschriben wurde

  Alt 13. Sep 2014, 09:33
Für nicht abstrakte Methoden geht in FPC mit {$mode objfpc} auch
Delphi-Quellcode:
type
 TBaseClass = class
  public
   procedure DoSomething; virtual; //abstract;
            //darf nicht abstract sein sonst fehlt symbol fuer linker
   constructor Create;
 end;

type
 TWorkClass = class(TBaseClass)
  public
   procedure DoSomething; override;
 end;
 
constructor TBaseClass.Create;
begin
 if TMethod(@DoSomething).Code <> Pointer(@TBaseClass.DoSomething) then begin
  DoSomething();
 end;
end;
Mit {$mode delphi} wird es zu
Delphi-Quellcode:
type
 TBaseClass = class
  public
   procedure DoSomething; virtual; //abstract;
            //darf nicht abstract sein sonst fehlt symbol fuer linker
   constructor Create;
 end;

type
 TWorkClass = class(TBaseClass)
  public
   procedure DoSomething; override;
 end;
 procty = procedure() of object;
  
constructor TBaseClass.Create;
begin
 if TMethod(procty(DoSomething)).Code <> Pointer(@TBaseClass.DoSomething) then begin
  DoSomething();
 end;
end;
welches vielleicht auch in Delphi funktioniert.
Martin Schreiber
  Mit Zitat antworten Zitat