Okay, Sorry ist wohl etwas vom ursprünglichen Thema abgewichen, dann wieder zurück zu TCollection.
Ich habe jetzt versucht, dass beim Programmstart 6 Threads erstellt werden und in einer TCollection gespeichert werden. Hier mal der Code dazu
Delphi-Quellcode:
TMyThread =
class(TThread)
protected
counter: integer;
procedure Execute;
override;
procedure prog;
public
constructor Create;
end;
TThreadItem =
class(TCollectionItem)
private
FLength: integer;
public
constructor Create(ACollection: TCollection);
override;
published
property Length: integer
read FLength
write FLength;
end;
TThreadlist =
class(TCollection)
private
procedure SetItems(
Index: integer; AValue: TThreadItem);
public
constructor Create;
function GetItems(
Index: integer): TThreadItem;
function AddEx(
ite: TMyThread): TThreadItem;
property Items[
Index: integer]: TThreadItem
read GetItems
write SetItems;
default;
end;
implementation
constructor TThreadItem.Create(ACollection: TCollection);
begin
if Assigned(ACollection)
then
inherited Create(ACollection);
end;
constructor TThreadlist.Create;
begin
inherited Create(TThreadItem);
end;
constructor TMyThread.Create;
begin
inherited Create(True);
end;
function TThreadlist.GetItems(
Index: integer): TThreadItem;
begin
result := TThreadItem(
inherited Items[
index]);
end;
function TThreadlist.AddEx(
ite: TMyThread): TThreadItem;
begin
result :=
inherited Add
as TThreadItem;
end;
function TThreadlist.AddEx(
ite: TMyThread): TThreadItem;
begin
result :=
inherited Add
as TThreadItem;
end;
procedure TForm7.FormCreate(Sender: TObject);
var
i: integer;
Thread:
array [0..5]
of TMyThread;
p: TThreadItem;
begin
ThreadL := TThreadlist.Create;
for i := 0
to 5
do
begin
ListBox1.Items.AddObject('
Thread Nr. ' + IntToStr(i), TObject(i));
end;
for i := 0
to 5
do
begin
Thread[i]:=TMyThread.Create;
ThreadL.AddEx(Thread[i]);
end;
ShowMessage(IntToStr(ThreadL.Count));
end;
Ist das soweit richtig?