Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple controls on one component 1

Status
Not open for further replies.

jawa500

Programmer
Dec 18, 2002
8
EU
I am trying to write a Delphi 4 programme to display images as thumbnails with specific related info.

I have a panel as the base with image, label, and edit box controls etc on top. I want to create as many of these as required at runtime.

Looking at creating custom controls they seem to derive from one control and I do not see how to include multiple controls in one component.

Is this the correct way forward?
 
Hi,

I think you mean something like this:

procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
MyEdit: TEdit;
MyName: string;
begin
for i := 1 to 10 do
begin
MyEdit := TEdit.Create(Self);
Myedit.Name := 'MyEdit' + IntToStr(i);
MyEdit.Parent := Panel1;
MyEdit.Top := i * 25;
MyEdit.Left := 5;
end;
end;

Start an new project and put a Button and a Pannel on the form. Put StdCtrls in the uses clause.

Put the code in the onClick event of the button.
With an image you replace Tedit with Timage and load everytime a picture from the directorie.

Steph [Bigglasses]
 
Getting there...

Using the code in the reply I have managed to create as many 'myPanels' as I need on top of a 'MainPanel'.

I am now trying to add other controls to each of the created 'myPanels' but can't assign the myPanelxxx parent name to these controls. I get the error 'Incompatible types TWinControl and String'.

Sample code within a FOR loop to create required number of myPanels at position x,y on MainPanel. The code below should place a label on each of the new myPanels;

MyPanel := TPanel.Create(Self);
MyPanel.Name := 'MyPanel' + IntToStr(z);
MyPanel.Parent := MainPanel;
MyPanel.left := x;
MyPanel.top := y;
MyPanel.width := 126;
MyPanel.height := 160;

MyLabel := TLabel.Create(Self);
MyLabel.Name := 'MyLabel' + IntToStr(z);
MyLabel.Parent := 'MyPanel' + IntToStr(z);
MyLabel.left := 4;
MyLabel.top := 4;
MyLabel.Caption := IntToStr(z);


The error is generated in line;
MyLabel.Parent := 'MyPanel' + IntToStr(z);

I tried;
MyLabel.Parent := MyPanel.Name

but got the error that TWinControl and TComponentName were incompatible.

How do I reference the newly created control as a parent?
 
hi,

procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
MyEdit: TEdit;
MyPanel: Tpanel;
MyName: string;
MyName2: string;
begin
for i := 1 to 10 do
begin
MyPanel := TPanel.Create(Self);
MyPanel.Name := 'MyPanel' + IntToStr(i);
MyPanel.Parent := Form1;
MyPanel.left := 100;
MyPanel.top := i * 35;
MyPanel.width := 126;
MyPanel.height := 30;

MyEdit := TEdit.Create(self);
Myedit.Name := 'MyEdit' + IntToStr(i);
MyEdit.Top := 2;
MyEdit.Left := 2;

MyPanel.InsertControl(MyEdit); // this places the edit on the last created panel

end;
end;

Steph [Bigglasses]
 
Hi,

MyPanel := TPanel.Create(Self);
MyPanel.Name := 'MyPanel' + IntToStr(z);
MyPanel.Parent := MainPanel;
MyPanel.left := x;
MyPanel.top := y;
MyPanel.width := 126;
MyPanel.height := 160;

MyLabel := TLabel.Create(Self);
MyLabel.Name := 'MyLabel' + IntToStr(z);
//*************************************
//MyLabel.Parent := 'MyPanel' + IntToStr(z);
//*************************************
// "MyLabel.Parent" is a Pointer, you can't assign
// a string to it!
MyLabel.Parent := MyPanel;

MyLabel.left := 4;
MyLabel.top := 4;
MyLabel.Caption := IntToStr(z);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top