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
Solved

Need help creating components dynamically

Posted on 1998-03-10
13
154 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
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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
FMX enumerated colours 2 115
Wincontrol not (correctly) drawn 15 40
Breakpoint doesn't stop in my variable 3 30
Firemonkey BASS_Init into a thread 17 30
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

860 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