?
Solved

Need help creating components dynamically

Posted on 1998-03-10
13
Medium Priority
?
159 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 480 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month9 days, 1 hour left to enroll

764 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