?
Solved

GetChildren is replicating the childrens in my DFM file.. why?

Posted on 2006-07-06
6
Medium Priority
?
524 Views
Last Modified: 2010-04-05
Hello!

First of all, let's understand what I'm doing. I'm writing a component that have N containers inside it, and inside every Container of this I have more N Containers.

When I did it I had a problem: The containers were not saved to my DFM. So, I've write the GetChildren override method:

-----------------
procedure TSuperCont.GetChildren(Proc: TGetChildProc;
  Root: TComponent);
var
   nAux: Integer;
begin
   inherited;

   for nAux := 0 to fTabs.Count - 1 do
      Proc( fTabs[ nAux ].fContainer );
end;
---------------

Wolaa!! It's saving to the DFM! But there is a problem. If I go to my form in Design time, and press ALT+F12 to see my DFM, there will be 2 containers (because I have 2 fTabs). THen I go back to my form pressing ALT+F12 again. When I go back to my DFM pressing once again ALT+F12, there will be 4 containers. If I do all this again, there will be 6 containers.

It's replicating in the DFM my containers, I don't know why.. Can someone help me please?
Thank you!
0
Comment
Question by:teste123
[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
  • 3
  • 3
6 Comments
 
LVL 10

Accepted Solution

by:
atul_parmar earned 1820 total points
ID: 17050384
Hi,

If not (csLoading in AOwner.ComponentState) Then
Begin
  // create your child container here
End

Moreover, you also need to override the getChildParent and getChildOwner
0
 

Author Comment

by:teste123
ID: 17050464
Hi Atul_parmar, thanx for helping me..

If I do that when I'm creating my childs container, I get error when  I change from the Form
DFM and the Form resources. And also I didn't get the idea of overriding the GetChildparent and Owner

Thanx
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 17050928
Can you me tell the error message?

The GetChildParent and GetChildOwner are required otherwise Delphi will try to make the form to be the owner and parent of the child containers.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:teste123
ID: 17052283
atul_parmar, I've played with the ReadState overriding and solved my problem together with GetChildren. Thank you!

Can you please help me with something else?

I've addeded the [csAcceptsControls] to my ControlStyle, but when I drop a component from the Delphi Pallete to it, it does not assume my container as the parent of the new component. It's like if the component was dropped to the Form on the back of my container.

Do you know what can it be?

Thank you!
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 17056598
1. The cause might be with owner relationships. Make sure you have overrridden the constructor.
e.g.
    constructor Create(AOwner : TComponent); override;
2. you are calling the default constructor.
e.g.
constructor MyControl.Create(AOwner: TComponent);
begin
  inherited;
.... // your other code
end;
0
 

Author Comment

by:teste123
ID: 17057672
Thank you!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

777 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