Registriert seit: 20. Jan 2006
Ort: Lübbecke
11.453 Beiträge
Delphi 12 Athens
|
AW: Klassen-Typ als Parameter?
14. Sep 2017, 08:56
Ungefähr so:
Delphi-Quellcode:
TBaseClass = class of tBase;
TBase = class(TObject)
private
public
constructor Create(aXMLNode : IXMLNode); virtual; abstract; // abstract kann entfallen, wenn hier schon gemeinsamer Code hin kann
end;
TBaseDesc1 = class(TBase)
private
public
constructor Create(aXMLNode : IXMLNode); override;
destructor Destroy; override;
end;
TBaseDesc2 = class(TBase)
private
public
constructor Create(aXMLNode : IXMLNode); override;
destructor Destroy; override;
end;
function MakeInstance(vNL : IXMLNodeList; const MyNodeName: string, MyClass: TBaseClass): TBase;
var
node: IXMLNode;
begin
node := vNL.FindNode(MyNodeName);
if Assigned(node) then
begin
fBaseDescX := MyClass.Create(node);
end
else
begin
fBaseDescX := nil;
end;
end;
|