Solved

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

Posted on 2006-07-06
6
504 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

911 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

22 Experts available now in Live!

Get 1:1 Help Now