type
TComponentManager =
class
private
FWorkPanel:TComponent;
FControlList:TInterfaceList;
type
TIBasicMeta =
class of TIBasic;
function GetControl(
Index: Integer):IBasic;
procedure SetControl(
Index: Integer; AControl: IBasic);
procedure DisposeControls;
function GetClassType(AType: TComponentID): TIBasicMeta;
public
constructor Create;
property WorkPanel:TComponent
read FWorkPanel
write FWorkPanel;
procedure NewControl(AType:TComponentID;
AName,ATitle,AValue,AHint,AList:
string;
ALeft,ATop,AWidth,AHeight:Integer);
overload;
procedure NewControl(AClass: TIBasicMeta; AType: TComponentID;
AName,ATitle,AValue,AHint,AList:
string;
ALeft,ATop,AWidth,AHeight:Integer);
overload;
function ReadControl(
const Id:Integer):TControl;
overload;
function ReadControl(
const Name:
String):TControl;
overload;
property Controls:TInterfaceList
read FControlList;
property Control[
Index:Integer]:IBasic
read GetControl
write SetControl;
function ControlCount:Integer;
destructor Destroy;
override;
end;
implementation
uses
// Api controls
uIEdit,uIComboBox,uIComboBoxList,uIPicture;
procedure TComponentManager.DisposeControls;
var I:Integer;
begin
for I := FControlList.Count -1
downto 0
do
begin
case IBasic(FControlList.Items[I]).IComponent
of
cEdit: TIEdit(FControlList.Items[I]).Free;
// error... klar, müsste mit IEdit zugreifen
cComboBox: TIComboBox(FControlList.Items[I]).Free;
cComboBoxList: TIComboBoxList(FControlList.Items[I]).Free;
cPicture: TIPicture(FControlList.Items[I]).Free;
end;
FControlList.Delete(I);
end;
end;
function TComponentManager.GetClassType(AType: TComponentID): TIBasicMeta;
begin
case AType
of
cEdit: result := TIEdit;
cComboBox: result := TIComboBox;
cComboBoxList: result := TIComboBoxList;
cPicture: result := TIPicture;
else
raise Exception.Create('
Unknown component');
end;
end;
procedure TComponentManager.NewControl;
begin
NewControl(GetClassType(AType),AType,AName,ATitle,AValue,AHint,AList,ALeft,ATop,AWidth,AHeight);
end;
procedure TComponentManager.NewControl;
var lBasic:IBasic;
begin
lBasic := AClass.Create(TWinControl( FWorkPanel ));
// funktioniert seltsamerweise wunderbar
with lBasic
do
begin
IComponent := AType;
Name := AName;
Title := ATitle;
Hint := AHint;
Left := ALeft;
Top := ATop;
Width := AWidth;
Height := AHeight;
Value := AValue;
// abstract
end;
case AType
of
cComboBox: TIComboBox(lBasic).List := AList;
// error... klar, müsste mit IComboBox zugreifen
cComboBoxList: TIComboBoxList(lBasic).List := AList;
end;
FControlList.Add( lBasic );
end;