Compound components (Panels inside Panels)?!

Hello experts,

the Delphi component I try to write (using Delphi 6) contains a panel which itself contains 2
more panels. I need to be able to drop other components onto theses
nested panels at design time which works fine but at runtime the
components on the nested panels are gone...

I came across different solutions with the setsubcomponent method and
having the form as the owner of all the panels but these solutions
didn't really work out. A solution that worked fine for me for having
all sorts of components on the top panel in my component was
overwriting the getchildren and getchildparent methods:

procedure TTestPanel.GetChildren(Proc: TGetChildProc; Root:
TComponent);
begin
  FNestedPanel.GetChildren(Proc,Root);
end;

function TTestPanel.GetChildParent: TComponent; override;
begin
  Result := FNestedPanel;
end;

I am sorry if this is a stupid question but this is my first try to write
my own component plus I'm fairly new to Delphi as well and I am stuck now when trying to use this solution
for having more than 1 nested panel as I cannot return Result := FNestedPanel anymore because I don't know which of my nested panels is the correct parent.

I hope anyone can help as I searched several newsgroups and came across different answers but none solved my problem and it is getting quite urgent now!

Many thanks for your help in advance!!!
Homer30Asked:
Who is Participating?
 
TheRealLokiConnect With a Mentor Senior DeveloperCommented:
or, since you are new, this might be a little more obvious

var
    newpanel: TPanel; // the new panel we wish to add inside "nestedpanel1"
begin
    newpanel := TPanel.Create(nestedpanel1); //owner
    newpanel.Parent := nestedpanel1; // note : "parent" is not the same thing as "owner"
    newpanel.top := 10;
    newpanel.left := 10;
    newpanel.width := 100;
    newpanel.height := 100;
end;

oh btw, if I'm on the wrong track, let me know. I've posted this because you said you were new to delphi, and it is easy to overlook it. If this is a different issue, feel free to "i know that, fool" me at will
0
 
TheRealLokiSenior DeveloperCommented:
you need to set the new component's "parent" property, or it will be invisible

e.g.
with tlabel.create(somepanel) do
begin
    parent := somepanel;
    left := 10;
    top := 10;
    caption := 'hi';
end;
0
 
saravananvgCommented:
Hello Sir,

  You need to use sendtoback and bringtofront for the panels to be shown and the remaining panels invisible.

with regards,
padmaja.
0
 
Kyle FosterCEOCommented:
Boy, I'm lost after reading this.  Delphi works in this way.  When you .CREATE a component you set the AOWNER in the Create(APanel).  This is so that APanel will destroy or release the memory for the new component.  Then COMPLETELY SEPERATE from the Owner is the Parent.  The parent is responsible for drawing the control so you must set the PARENT of the 2 sub panels to the main panel and then any thing dropped on one of the 2 sub panels need the appropriate panel as their parent.

I know that 2 answers above showed how to do this, but after reading this thread I had to explain this to myself, so I though it might help.  :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.