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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems using FindComponent 1

Status
Not open for further replies.

dktekno

Programmer
Feb 22, 2005
3
DK
I wrote this code:

TButton.Create(self).Name := 'Button1';

with TButton(FindComponent('Button1')) do
begin
top := 88;
left := 88;
height := 88;
width := 88;
Parent := somepanel;
end;

It works fine. It shows my newly created Button1.

But when I do the following:

TButton.Create(self).Name := 'Button1';

with TButton(FindComponent('Button1')) do
begin
top := 88;
left := 88;
height := 88;
width := 88;
Parent := TPanel(Findcomponent('somepanel'));
end;

which was supposed to be exactly the same, my button isn't showed. WHY?

I NEED the FindComponent thing because I somepanel to be a panel that is created runtime, but it seems like I can't get a component build at runtime to be a parent and show the components on it, or has it something to do with the FindComponent method? Because as you see, even though somepanel was created at design time, it won't show my button on it, if it's child has called its parent TPanel(Findcomponent('somepanel')) instead of somepanel.

How do I solve this?

I tried with BringToFront, it worked for some reason yesterday but today it doesn't... this is really strange. Please, help me!
 
You need to apply the FindComponent method to the form, not the button (which you are doing with with):
[tt]
Parent := TPanel(Self.Findcomponent('somepanel'));
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top