Solved

Adding TabSheets to PageControl component

Posted on 2000-04-27
8
442 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
  • 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
 
LVL 1

Author Comment

by:dcl
ID: 2761591
Thanks ITugay

I would never have found that!

I expect to have more questions soon.
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!

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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 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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 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

12 Experts available now in Live!

Get 1:1 Help Now