unit uFrameFactory;
interface
uses Projekt,
fBaseFrame, fLAFrame, fKSTFrame, fSTOFrame,
Controls, Classes, ADODB;
Type TBaseFrameClass =
class of TBaseFrame;
Type TBaseFrameClassRec =
record
Name:
String;
Header:
String;
Klasse:TBaseFrameClass;
end;
const FrameClassList:
Array[0..8
{ggf. erhöhen}]
of TBaseFrameClassRec =
(
(
Name: '
LA'; Header: '
Lohnarten'; Klasse: TLAFrame),
(
Name: '
KST'; Header: '
Kostenstellen'; Klasse: TKSTFrame),
//...
);
Type
TFrameFactory =
class
private
fParent : TWinControl;
fOwner : TComponent;
fCon : TADOConnection;
//...
function GetClassFromName(FrameName:
String):TBaseFrameClass;
function GetHeaderFromName(FrameName:
String):
String;
public
constructor create(Owner:TWinControl);
overload;
property Owner:TComponent
read fOwner;
property Parent:TWinControl
read fParent
write fParent;
property Con:TADOConnection
read fCon
write fCon;
function GetFrame(FrameName:
String):TBaseFrame;
end;
implementation
{ TFrameFactory }
constructor TFrameFactory.create(Owner: TWinControl);
begin
inherited create;
fOwner:=Owner;
end;
function TFrameFactory.GetClassFromName(FrameName:
String): TBaseFrameClass;
var
i: Integer;
begin
Result:=nil;
for i := 0
to High(FrameClassList)
do
if FrameClassList[i].
Name = FrameName
then
begin
Result := FrameClassList[i].Klasse;
break;
end;
end;
function TFrameFactory.GetHeaderFromName(FrameName:
String):
String;
var
i: Integer;
begin
Result:='
';
for i := 0
to High(FrameClassList)
do
if FrameClassList[i].
Name = FrameName
then
begin
Result := FrameClassList[i].Header;
break;
end;
end;
function TFrameFactory.GetFrame(FrameName:
String): TBaseFrame;
var f:TBaseFrame;
begin
f:=GetClassFromName(FrameName).Create(Owner);
f.Parent:=Parent;
f.Align:=alClient;
f.Con:=Con;
f.Header:=GetHeaderFromName(FrameName);
//...
Result:=f;
end;
end.