Solved

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

Posted on 2006-07-06
6
501 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

13 Experts available now in Live!

Get 1:1 Help Now