Solved

Need help creating components dynamically

Posted on 1998-03-10
13
149 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
13 Comments
 
LVL 2

Accepted Solution

by:
Waldek earned 120 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:ermac
Comment Utility
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
Comment Utility
To access them write:

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

Expert Comment

by:Waldek
Comment Utility
Ronit has right .
 IF (FindComponent('Panel1') is TPanel ) then .....
 
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:ermac
Comment Utility
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
Comment Utility
Wait , trying
0
 
LVL 5

Expert Comment

by:julio011597
Comment Utility
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
Comment Utility
Yes, tahts right
Set Panel1.Parent:=Panel_Parent;

0
 

Author Comment

by:ermac
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks a lot!!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now