Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Objs dinamicaly

Status
Not open for further replies.

tvidigal

Programmer
Sep 8, 2003
19
0
0
PT
Hi,
i have

var myP: array[0..kMaxPanels-1] of TPanel;

then

procedure DrawPanelsFromTracks_Click(Sender : TObject);
var i : integer;
begin
for i:=0 to kMaxPanels-1 do
begin
myP:=TPanel.Create(self); {works just fine}
myP.Tag:=i; {crashes or other thing}
end;
end;

what i'm doing wrong here??
how can i create objects dinamically and show then on form!

thanks in advance
 
Assuming that was

Code:
myP[i].Tag := i;

then try

Code:
(myP[i] As TPanel).Tag := i;
 
or on declaration:
myP : TPanel;

that way you don't have to cast the object as TPanel when you want to operate on it.

Brian
"There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group." - tag line I stole
 
var myP: array[0..kMaxPanels-1] of TPanel;

then

procedure DrawPanelsFromTracks_Click(Sender : TObject);
var i : integer;
begin
for i:=0 to kMaxPanels-1 do
begin
myP := TPanel.Create(self);
myP.Parent := self;
myP.Tag:=i;
end;
end;
 
you need to make sure you set the Parent property of any dynamically created visual controls (there are some exceptions)...otherwise they don't show up.
 
Geez guys

thank you!!

BillDoorNz you'r great dude!!

regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top