Re: Object array
Posted by Feier Vlad on October 01, 2003 at 21:41:09:
In Reply to: Object array posted by Constantin on October 01, 2003 at 08:47:11:
: how to create component to have an array
Well... your problem will be solved while the program is running. You must create components by writing, not by drawing them on form1. To create a single component you write this:
var comp:TComponent; ... begin ... comp := Tcomponent.Create(form); comp.parent := form; ...
var l:TLabel; ... begin ... l:=TLabel.Create(form1); l.parent:=form1; //set the parent of comp with l do begin top := 50; left := 50; width := 200; height := 20; caption := 'This is the new label'; show; end; ...
If you want to create an array of objects you must create them one by one:
var l:array[1..10] of TLabel; ... begin ... for i: = 1 to 10 do begin l[i] := TLabel.Create(form1); l[i].parent := form1;
with l[i] do begin top := i*20; left := 50; height := 20; width := 200; caption := 'A new label'; show; end; end;
Be sure you set the parent of your new component. You can set the parent another form (form2, ...) or a frame (frame21...).
Obs: Some components requires using of their special units (if you create a component
TImage and load an image from a *.jpg file, you must write in the uses section 'uses
..., jpeg, ...')
[ DelphiLand: free Delphi source code, tips, tutorials ]