Solved

Compound components (Panels inside Panels)?!

Posted on 2006-06-13
6
233 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now