[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Need help creating components dynamically

Posted on 1998-03-10
13
Medium Priority
?
160 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Independent Software Vendors: 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

649 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