Einzelnen Beitrag anzeigen

Benutzerbild von Uwe Raabe
Uwe Raabe

Registriert seit: 20. Jan 2006
Ort: Lübbecke
11.021 Beiträge
 
Delphi 12 Athens
 
#4

AW: Abstrakte Methode mit Enum -> Unterschiedliche Definitionen

  Alt 17. Jun 2017, 16:05
Du könntest es auch über ein overload regeln:

Delphi-Quellcode:
type
  TSrvCmd = (Command1, Command2);

type
  TMKCustomClient = class
  protected
    procedure DoOnServerCommand(ServerCommand : TSrvCmd; Data : TStream); virtual; abstract;
  end;

type
  TSrvCmd2 = (Command1a, Command2a, Command3, Command4, Command5);

type
  TMKChatClient = class(TMKCustomClient)
  protected
    procedure DoOnServerCommand(ServerCommand : TSrvCmd; Data : TStream); override; overload;
    procedure DoOnServerCommand(ServerCommand : TSrvCmd2; Data : TStream); overload;
  end;

procedure TMKChatClient.DoOnServerCommand(ServerCommand: TSrvCmd; Data: TStream);
begin
  { hier setzen wir voraus, daß die Ordnungszahlen der ersten beiden Werte von TSrvCmd2 denen von TSrvCmd entsprechen }
  DoOnServerCommand(TSrvCmd2(ServerCommand), Data);
end;

procedure TMKChatClient.DoOnServerCommand(ServerCommand: TSrvCmd2; Data: TStream);
begin
  case ServerCommand of
    Command1a: ;
    Command2a: ;
    Command3: ;
    Command4: ;
    Command5: ;
  end;
end;
Uwe Raabe
Certified Delphi Master Developer
Embarcadero MVP
Blog: The Art of Delphi Programming
  Mit Zitat antworten Zitat