Einzelnen Beitrag anzeigen

Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#12

AW: Mehrere Klassen von einer Klasse ableiten

  Alt 28. Apr 2012, 15:31
Delphi-Quellcode:
unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, BaseUnit;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
    MyDevice : TBaseClass;
  end;

var
  Form1: TForm1;

implementation

uses Unit1;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
    MyDevice:=TBaseClassClass(FindClass('TDeviceModule1')).Create(Self);
end;

end.

BaseUnit:

unit BaseUnit;

interface

uses SysUtils, Classes;

type
  TBaseClassClass=Class Of TBaseClass;
  TBaseClass = class (TDataModule)
  protected
    procedure DoSomethingImportant; virtual; abstract;
    procedure DoSomethingMoreImportant; virtual; abstract;
    procedure DoSomethingEvenMoreImportant; virtual; abstract;
  end;

implementation

end.

Unit1:

unit Unit1;

interface

uses
  SysUtils, Classes,Forms,BaseUnit;

type
  TDeviceModule1 = class(TBaseClass)
  procedure ShowMsg (Msg:String);
    procedure DataModuleCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  DeviceModule1: TDeviceModule1;

implementation

{$R *.dfm}

procedure TDeviceModule1.DataModuleCreate(Sender: TObject);
begin
     ShowMsg('Create');
end;

procedure TDeviceModule1.ShowMsg (Msg:String);
begin
  Application.MessageBox(PChar(Msg),'Module1');
end;

initialization
RegisterClasses([TDeviceModule1]);

end.
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat