Solved

Adding TabSheets to PageControl component

Posted on 2000-04-27
8
454 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
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.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Mydac connection data base issue 3 157
Firemonkey webbrowser scrollbars ? 1 38
Delphi...Split view - idea? 1 68
Twebbrowser add css to the header 3 25
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 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