?
Solved

Adding TabSheets to PageControl component

Posted on 2000-04-27
8
Medium Priority
?
476 Views
Last Modified: 2010-04-04
I want to make a pagecontrol component with several tabsheets on it.
When I try to place it on a form, I get an error "Control '' has not parent window".

His is my Create method for the pagecontrol component.

begin
 inherited Create(AOwner);
 Height   := 280;
 Width    := 580;
 tbsPage1 := TTabSheet.create(Self);
 tbsPage1.PageControl := Self;
end;

As soon as I add the .PageControl line of code, I can no longer add the component to any forms.
What am I doing wrong?
0
Comment
Question by:dcl
[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
  • 4
  • 3
8 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2758235
hi dcl,

you must set a parent for the pagecontrol and the tabsheet.

we´ll, the parent for the pagecontrol is done in the inheritance-call.

guessing u must only set the parent for the tabsheet. try this change:

begin
 inherited Create(AOwner);
 Height   := 280;
 Width    := 580;
 tbsPage1 := TTabSheet.create(Self);
 tbsPage1.PageControl := Self;
 tbsPage1.Parent      := Self;
end;

meikl
0
 
LVL 9

Accepted Solution

by:
ITugay earned 400 total points
ID: 2758397
hi all.


dcl, the problem is that you can't insert TTabSheet in TPageControl while it have no parent defined. The parent will be defined only after parent of TPageControl calls method InsertControl. To hook this moment I suggest you detect CM_PARENTCTL3DCHANGED command. This command occurs when parent to TPageControl calls self InsertControl method.
Try code bellow, it' works.

-------
type
  TMyPageControl = class(TPageControl)
    tbsPage1 : TTabSheet;
    constructor Create(aOwner : TComponent); override;
    procedure   WndProc(var MSG : TMessage); override;
  end;

constructor TMyPageControl.Create(aOwner : TComponent);
begin
 inherited Create(AOwner);
 Height   := 280;
 Width    := 380;
end;

procedure   TMyPageControl.WndProc(var MSG : TMessage);
begin
  inherited;
  if (MSG.MSG = CM_PARENTCTL3DCHANGED)
  and (tbsPage1 = nil) then  // prevent duplicate initialization
  begin
   tbsPage1 := TTabSheet.create(Self);
   tbsPage1.PageControl:=Self;
   tbsPage1.Caption:='000';
  end;
end;

// use it as test to be sure it work
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
  TM := TMyPageControl.Create(Self);
  InsertControl(TM);
end;

----
Igor
0
 
LVL 1

Author Comment

by:dcl
ID: 2761588
Adjusted points from 50 to 100
0
Industry Leaders: 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!

 
LVL 1

Author Comment

by:dcl
ID: 2761591
Thanks ITugay

I would never have found that!

I expect to have more questions soon.
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2761684
always welcome;)
0
 
LVL 1

Author Comment

by:dcl
ID: 2765374
Igor,
Is it the parent's InsertControl method that is being run, or the PageControls?
I am trying to fnd a place I can call a "AddPages" method to a PageControl Class, to make this easy next time
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2765460
Well, in my sample I have detected a moment when parent of PageControl calls it's method InsertControl. I mean "parent" is for example TForm where TPageControl have placed.

//TForm.InsertControl(PageControl)

At first sight it would be necessary to override TPageControl.SetParent method, but InsertControl doesn't call it.

The sample I showed you not seems like a right way to add page to PageControl, it look like some trick, but it work. The deal is that TTabSheet is inherits from TWinControl, and had be added inside TPageControl.Constructor but TPageControl have different  from usual mechanism to insert controls (add pages). It tries to make a page visible just after TTabSheet.PageControl property have been assigned. And error occurs when it tries to make control visible without right chain of parents.

To make it easy.... Ok, I shall think about, and let you know when be ready.
----
Igor.
0
 
LVL 1

Author Comment

by:dcl
ID: 2767916
Thanks for your time Igor
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

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…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

752 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