Solved

Adding TabSheets to PageControl component

Posted on 2000-04-27
8
463 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 100 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

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!

Question has a verified solution.

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

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…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

756 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