Solved

Adding TabSheets to PageControl component

Posted on 2000-04-27
8
472 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
Independent Software Vendors: 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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

724 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