Solved

Compound components (Panels inside Panels)?!

Posted on 2006-06-13
6
236 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
  • 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 500 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

Title # Comments Views Activity
FMX enumerated colours 2 117
Can Viruses spread while transferring Binary data with Winsock 2 89
Delphi inherited method 6 76
How to convert memory stream to PDF file 6 112
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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
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…

837 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