Solved

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

Posted on 2006-07-06
6
510 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
  • 3
  • 3
6 Comments
 
LVL 10

Accepted Solution

by:
atul_parmar earned 455 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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 video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

860 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