Solved

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

Posted on 2006-07-06
6
506 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to renew a Delphi rad-studio licence? 5 65
How to define IfThen functions in one common unit? 4 54
Delphi Yen format 3 35
Dynamically Created Query 3 55
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

772 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