unit UDataTypes;
interface
uses Classes;
type
tComp =
class(TComponent)
private
Id: word;
Name:
String;
public
function GetId: Word;
procedure SetId(Value: Word);
function GetName:
String;
procedure SetName(Value:
String);
constructor Create(anId: word; aName:
String);
overload;
end;
tComponentList =
class(TComponent)
private
MyComps:
array of tComp;
function IssetComp(CompId : Word) : BOOLEAN;
public
function GetCompById(CompId : WORD) : tComp;
function GetCompByName(CompName :
String) : tComp;
procedure AddComp(AComp : tComp);
procedure DelComp(CompId : WORD);
function CompCount: integer;
end;
implementation
{##############################################################################}
{############################ tMyComp-Routinen ################################}
{##############################################################################}
constructor tComp.Create(anId: word; aName:
String);
begin
Self.SetId(anId);
Self.SetName(aName);
end;
function tComp.GetId: Word;
begin
GetId:=Self.Id;
end;
procedure tComp.SetId(Value: Word);
begin
Self.Id:=Value;
end;
function tComp.GetName:
String;
begin
GetName:=Self.
Name;
end;
procedure tComp.SetName(Value:
String);
begin
Self.
Name:=Value;
end;
{##############################################################################}
{########################### tComponentList-Routinen ##########################}
{##############################################################################}
procedure TComponentList.AddComp(AComp: tComp);
begin
SetLength(Self.MyComps,Length(Self.MyComps)+1);
MyComps[High(MyComps)]:=AComp;
Self.Owner.InsertComponent(AComp);
end;
procedure TComponentList.DelComp(CompId: word);
var i: integer;
begin
if (IssetComp(CompId))
then
begin
Self.Owner.RemoveComponent(Self.GetCompById(CompId));
for i:=CompId
to CompCount-2
do
begin
Self.MyComps[i].Free;
Self.MyComps[i]:=tComp.Create(Self.GetCompById(i+1).GetId,Self.GetCompById(i+1).GetName);
end;
Self.MyComps[CompCount-1].Free;
SetLength(Self.MyComps,CompCount-1);
end;
end;
function TComponentList.IssetComp(CompId: word): Boolean;
var
i : word;
tmpBool : boolean;
BEGIN
tmpBool:=false;
if(Self.CompCount <> 0)
THEN
Begin
i := 0;
repeat
if(Self.MyComps[i].GetId = CompId)
THEN tmpBool:=TRUE;
inc(i);
until ((i>=Self.CompCount-1)
OR (tmpBool = TRUE));
End;
IssetComp:=tmpBool;
END;
function TComponentList.CompCount: Integer;
begin
Result:=Length(Self.MyComps);
end;
function TComponentList.GetCompById(CompId: word): tComp;
begin
if( IssetComp(CompId) )
THEN
GetCompById:=Self.MyComps[CompId]
else
GetCompById:=nil;
end;
function TComponentList.GetCompByName(CompName:
String): tComp;
VAR
i : WORD;
tmpBool : BOOLEAN;
tmpComp: tComp;
BEGIN
tmpBool:=FALSE;
tmpComp:=nil;
if(Self.CompCount <> 0)
THEN
Begin
i := 0;
repeat
if(Self.MyComps[i].GetName = CompName)
THEN
Begin
tmpBool:=TRUE;
tmpComp := Self.MyComps[i];
End
else tmpComp :=
nil;
inc(i);
until ((i>=CompCount-1)
OR (tmpBool = TRUE));
End;
GetCompByName:=tmpComp;
END;
end.