unit myFormComponent;
interface
uses
SysUtils, Classes, Controls, StdCtrls, forms;
type
TMyForm = class(TForm)
public
function getDisplayValue: string;
end;
TMdMyItem = class (TCollectionItem)
private
FCode: Integer;
FForm: TCustomForm;
procedure SetForm(const Value: TCustomForm);
published
property Form: TCustomForm read FForm write SetForm;
end;
TMdMyCollection = class (TCollection)
private
FComp: TComponent;
FCollString: string;
public
constructor Create (CollOwner: TComponent);
function GetOwner: TPersistent; override;
procedure Update(Item: TCollectionItem); override;
end;
TmyFormComponent = class(TComponent)
private
FForm: TMyForm;
FColl: TMdMyCollection;
function GetCollString: string;
procedure SetMoreData(const Value: TMdMyCollection);
protected
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Form: TMyForm read FForm write FForm;
property MoreData: TMdMyCollection read FColl write SetMoreData;
property CollString: string read GetCollString;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Beispiele', [TmyFormComponent]);
end;
{ TMyForm }
function TMyForm.getDisplayValue: string;
begin
result := TMyForm.ClassName;
end;
{ TMdMyCollection }
constructor TMdMyCollection.Create (CollOwner: TComponent);
begin
inherited Create (TMdMyItem);
FComp := CollOwner;
end;
function TMdMyCollection.GetOwner: TPersistent;
begin
Result := FComp;
end;
procedure TMdMyCollection.Update(Item: TCollectionItem);
var
str: string;
i: Integer;
begin
inherited;
// update everything in any case...
str := '';
for i := 0 to Count - 1 do
begin
str := str + (Items [i] as TMdMyItem).ClassName;
if i < Count - 1 then
str := str + '-';
end;
FCollString := str;
end;
{ TMdMyItem }
procedure TMdMyItem.SetForm(const Value: TCustomForm);
begin
end;
{ TmyFormComponent }
constructor TmyFormComponent.Create(AOwner: TComponent);
begin
inherited;
FForm := TMyForm.Create(AOwner);
FColl := TMdMyCollection.Create(Self);
end;
destructor TmyFormComponent.Destroy;
begin
FForm.Free;
FForm := nil;
FColl.Free;
inherited;
end;
procedure TmyFormComponent.SetMoreData(const Value: TMdMyCollection);
begin
FColl.Assign(Value);
end;
function TmyFormComponent.GetCollString: string;
begin
Result := FColl.FCollString;
end;
end.