?
Solved

Compound components (Panels inside Panels)?!

Posted on 2006-06-13
6
Medium Priority
?
241 Views
Last Modified: 2010-04-05
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!!!
0
Comment
Question by:Homer30
[X]
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
  • 2
6 Comments
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 16899075
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
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 2000 total points
ID: 16899098
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
 
LVL 6

Expert Comment

by:saravananvg
ID: 16899992
Hello Sir,

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

with regards,
padmaja.
0
 
LVL 7

Expert Comment

by:kfoster11
ID: 16908972
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month11 days, 17 hours left to enroll

752 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