I've always found dynamically created components very powerful when you
need many similar components on a form, and want to process them with a
loop.
But I've never used TComponent list to store the details - instead I
create arrays of components which works very well.
Maybe using TComponent is a good idea - I never got round to trying it.
I use an array of components thus: (in this example I am creating
TEdit components).
// Declare an array for Dynamically created components:
fB : Array[1..nBands] of TEdit;
Then just say: (depending on what properties you want to set.....)
for I:=1 to nBands do begin
fB[I]:=TEdit.Create(Self); // Create TEdit
fB[I].Parent:=MyForm; fB[I].OnChange:=AnyChange;
fB[I].Left:=EL; fB[I].Top:=T+12*I; fB[I].Width:=60;
fB[I].OnKeyPress:=NumFldKeyPress; // key press routine
fB[I].OnExit:=NumFldExit; // This is an edit routine on exit
end;
Now you can access (say) the third component (and of course its
properties) as fB[3] at any time, process them all in a loop etc at any
time.
If you have lines each containing several linked components you can
declare the arrays using records thus:
RL : Array[1..53] of Record { 3 TEdits per line. }
rSDate : TEdit;
rName : TEdit;
rAdd : TEdit;
end; {endRecord}
This makes it very easy to create very powerful forms and code.
Maybe this would work for you?
Regards,
Brendan Blake.
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of John Barrat
Sent: 15 February 2007 18:30
To: 'Borland's Delphi Discussion List'
Subject: Help needed Using TComponentList
I am writing an application which needs to create a number of components
(all of the same type - a custom ComboBox). To manage these I have been
tryig to use TComponentList but having added these to a TComponentList I
cannot see how I access there components.
e.g.
mCommands := TComponentList.Create; // create the component list
// create a new component and add it to the ComponentList.
mComIdx := mCommands.Add(TMacroCombo.Create(Self, cCommand));
Now how do I access the properties of the component I have just added?
I had assumed I could do something like this....
With mCommands[index] do begin
align := alLeft;
ItemIndex := 0;
etc...
end
Have I misunderstood completely on how this class is used?
JohnB
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi