Einzelnen Beitrag anzeigen

Ghostwalker

Registriert seit: 16. Jun 2003
Ort: Schönwald
1.299 Beiträge
 
Delphi 10.3 Rio
 
#11

AW: Konzeptfrage: Interface oder Messages

  Alt 9. Nov 2016, 16:42
und noch ein wenig Code zum Beispiel, in welche Richtung hier meine Gedanken gehen:

Dat Interface:

Delphi-Quellcode:
TYPE
   TMasterData = record
                  id : integer;
                  status : integer;
                  text : String;
   end;

   IDetail = INTERFACE;

   IMaster = Interface
     PUBLIC
       function getItem(index:integer):TMasterData;
       procedure setItem(const index:integer;const data:TMasterdata);
       Property Items[index:integer]:TMasterData read getItem write setItem;

       procedure setDetail(element:IDetail);
       Property Detail:IDetail write setDetail;

       Procedure NewElement(data:TMasterdata);
       Procedure DeleteElement(data:TMasterdata);
   End;

   IDetail = Interface
     PUBLIC

       Procedure SetMaster(element:IMaster);

       Property Master:IMaster write setMaster;

       Procedure AddNew();
       Procedure Edit(id:integer);
       procedure Delete(id:integer);
   End;
Da Master
Delphi-Quellcode:
uses
   MyInterfaces;

TYPE
  PMasterdata = ^TMasterdata;

  TNavi = class(TObject,IMaster)
    PRIVATE
       datalist : TList;
    PROTECTED
       :
       :
       :
    PUBLISHED
       :
       :
       :
    PUBLIC

      function getItem(index:integer):TMasterData;
      procedure setItem(const index:integer;const data:TMasterdata);
      Property Items[index:integer]:TMasterData read getItem write setItem;

      procedure setDetail(element:IDetail);
      Property Detail:IDetail write setDetail;

      Procedure NewElement(data:TMasterdata);
      Procedure DeleteElement(data:TMasterdata);
  end;
Ein PKW
Delphi-Quellcode:
uses
  MyInterface;

TYPE
  TPKW = Class(TObject,IDetail)
    PRIVATE
       ffarbe : Tcolor;
       fleistung: Integer;
       fmarke : TPKWMarke;
       fstatus: integer;
       fid : integer;

    PROTECTED
    PUBLISHED
      property Farbe:TColor read ffarbe write ffarbe;
      property Leistung:integer read fleistung write fleistung
      property Marke : TPKWMarke read fmarke write fmarke
      Property ID:integer read fid write fid;
    PUBLIC
     Procedure SetMaster(element:IMaster);

     Property Master:IMaster write setMaster;

     Procedure AddNew();
     Procedure Edit(id:integer);
     procedure Delete(id:integer);

  End;
Ein Hoverboard
Delphi-Quellcode:
uses
  MyInterface;

TYPE
  THoverboard = Class(TObject,IDetail)
    PRIVATE
       fid : integer;
       fstatus : integer;
       fname : string;
       fflughoehe : integer;
       fakkuleistung : double;

    PROTECTED
    PUBLISHED
      Property ID:integer read fid write fid;
      property Status: integer read fstatus write fstatus;
        :
        :
    PUBLIC
     Procedure SetMaster(element:IMaster);
     Property Master:IMaster write setMaster;

     Procedure AddNew();
     Procedure Edit(id:integer);
     procedure Delete(id:integer);

  End;
Nur mal zur Verdeutlichung grob hingezimmert.
Uwe
e=mc² or energy = milk * coffee²
  Mit Zitat antworten Zitat