Einzelnen Beitrag anzeigen

Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#3

Re: Zwei Klassen in einer ObjectList

  Alt 28. Mai 2010, 17:25
Hallo und Willkommen im Land der Objektorientierung

Du leitest einfach TProt2 von TProt1 ab:

Delphi-Quellcode:
type
 TProt1 = class
    protected
      procedure MachWasAB; virtual;
    public
      constructor create; virtual;
      procedure Send(const Buf : Array of byte); virtual;
      procedure Verarbeite; virtual;
  end;

  TProt2 = class(TProt1)
    protected
      procedure MachWasABC; override;
    public
      constructor create; override;
      procedure Send(Const Buf : Array of Byte); override;
      procedure Verarbeite; override;
  end;

Var
  ClientList: TObjectList<TProt1>;
oder erstellst eine (abstrakte) Oberklasse:

Delphi-Quellcode:
type
 TProt = class abstract
    protected
      procedure MachWasAB; virtual; abstract;
    public
      procedure Send(const Buf : Array of byte); virtual; abstract;
      procedure Verarbeite; virtual; abstract;
  end;

  TProt1 = class(TProt)
    protected
      procedure MachWasAB; override;
    public
      constructor create; virtual;
      procedure Send(const Buf : Array of byte); override;
      procedure Verarbeite; override;
  end;

  TProt2 = class(TProt1)
    protected
      procedure MachWasABC; override;
    public
      constructor create; override;
      procedure Send(Const Buf : Array of Byte); override;
      procedure Verarbeite; override;
  end;

Var
  ClientList: TObjectList<TProt>;
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat