Solved

Need help creating components dynamically

Posted on 1998-03-10
13
157 Views
Last Modified: 2010-04-06
I need some help creating components (TPanel) dynamically. And how do I create them on top of an TPanel component (Created during design time)

I also need to keep track (access) them

For your information, I'm using Delphi 3.0 running on Windows 95

Thanks in Advance,
Ermac


0
Comment
Question by:ermac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 2

Accepted Solution

by:
Waldek earned 120 total points
ID: 1360360
You must make this in code:
 var panel:TPanel;
 begin
  Panel:=TPanel.Create(Panel_Parent);
  // You must in create set a parent for new panel
  // Then You must set other info
   with Panel do
   begin
    Name:='Panel.....';
    Caption:= ....
    SetBounds(1,1,100,100);
    Align:=alClient
    // and other
   end;
end;
Because a panel has parent You don't free it on end
0
 

Author Comment

by:ermac
ID: 1360361
But how do I access them?? (Eg. 10 Panels)
I can set the name by

var
  PanelCount : integer;
begin
  PanelCount := 0;
  with Panel do
  begin
     Name:='Panel' + IntToStr(PanelCount);
     Inc(PanelCount);
     ...
  end;

But how do I access them??


0
 
LVL 2

Expert Comment

by:Waldek
ID: 1360362
You must create ten panels before set a name for every.
You must use a construction Panel1.caption:= ... , panel2.Caption:= .... etc.etc . If I good recognize Your question
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ermac
ID: 1360363
But the thing is that I don't know how many Panels to create until runtime i.e. when the user enters a number in the edit box followed by the OK button

Hope you could understand what I meant...
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1360364
To access them write:

with TPanel(FindComponent('put the panel's name here')) do
begin
...
end;
0
 
LVL 2

Expert Comment

by:Waldek
ID: 1360365
Ronit has right .
 IF (FindComponent('Panel1') is TPanel ) then .....
 
0
 

Author Comment

by:ermac
ID: 1360366
I've tried the code but it doesn't work...

I've created a Panel (Name is ParentPanel) during design time and here's the code
var
  Panel:TPanel;
begin
  Panel:=TPanel.Create(ParentPanel);
  with Panel do
  begin
    Name:='Panel1';
    Caption:= '';
    Align:=alClient;
    Color := clBlue;
  end;
end;

but the panel doesn't shows up. Why??
0
 
LVL 2

Expert Comment

by:Waldek
ID: 1360367
Wait , trying
0
 
LVL 5

Expert Comment

by:julio011597
ID: 1360368
I guess you need to set the "Parent" property.

BTW, the "keep track of panels" stuff couldn't be handled by a TList?
0
 
LVL 2

Expert Comment

by:Waldek
ID: 1360369
Yes, tahts right
Set Panel1.Parent:=Panel_Parent;

0
 

Author Comment

by:ermac
ID: 1360370
I've finally got it to work... :-)
Thanks Julio and Waldek

Any idea on how to use TList?? (how do I add TPanel objects into it and how do I access them?)

Will increase points if you can answer that
Ermac
0
 
LVL 2

Expert Comment

by:Waldek
ID: 1360371
Try this
var
  MyList: TList;
  Panel1,Panel2: TPanel;
  B:byte;
begin
  MyList := TList.Create;
  Panel1:=TPanel.Create(Self);
  Panel2:=TPanel.Create(Self);
  Panel1.Name:='One';
  MyList.Add(Panel1);
  Panel2.Name:='Two';
  MyList.Add(Panel2);

  for B := 0 to (MyList.Count - 1) do

  begin
     MessageDlg('Panel '+TPanel(MyList.Items[B]).Name, mtInformation,
      [mbOk], 0);
  end;
 Panel1.Free;
 Panel2.Free;
 MyList.Free;
end;
0
 

Author Comment

by:ermac
ID: 1360372
Thanks a lot!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question