unit AComponent;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TAComponent = class(TComponent)
private
{ Private declarations }
FItems:array of TComponent;
procedure SetItem(index:integer;Value:TComponent);
function GetItem(index:integer):TComponent;
procedure SetCount(Value:integer);
function GetCount:integer;
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AComponent:TComponent);override;
property Count:integer read GetCount write SetCount;
property Items[index:integer]:TComponent read GetItem write SetItem;
published
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TAComponent]);
end;
{ TAComponent }
constructor TAComponent.Create(AComponent: TComponent);
begin
inherited;
FItems:=nil;
SetCount(10);
end;
function TAComponent.GetCount: integer;
begin
Result:=High(FItems);
end;
function TAComponent.GetItem(index: integer): TComponent;
begin
if (index>High(FItems)) or (index<0) then
raise Exception.Create('Error Index');
Result:=FItems[index];
end;
procedure TAComponent.SetCount(Value: integer);
var
i:integer;
FCount:integer;
begin
if Value<0 then raise Exception.Create('Error Value');
FCount:=High(FItems)+1;
if Value<>0 then SetLength(FItems,Value) else FItems:=nil;
if Value>FCount then
for i:=FCount to High(FItems) do FItems:=nil;
end;
procedure TAComponent.SetItem(index: integer; Value: TComponent);
begin
if (index>High(FItems)) or (index<0) then
raise Exception.Create('Error Index');
FItems[index]:=Value;
end;
end.