Why TPageControl can't have control TSpeedButton as a child? lazarus / 31-LCL ---------------------------------------------------------------------- nadavvin · 2018-12-20 20:30 Hello https://i.imgur.com/ZfsEeSg.png Why TPageControl can't have control TSpeedButton as a child? ---------------------------------------------------------------------- Blaazen · 2018-12-20 20:50 Because it is created without csAcceptsControls in ControlStyle. Common use is that you will create some TabSheets on PageControl and you will paste components there. ---------------------------------------------------------------------- nadavvin · 2018-12-20 22:04 It is a button to add a tab and have hint and custom on click event. I still get the error when I set it: PageControlMain.ControlStyle:=[csAcceptsControls];   FBtnAddTab.Parent := PageControlMain; ---------------------------------------------------------------------- lucamar · 2018-12-20 22:52 A small demonstration (attached). The important code is this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormCreate(Sender: TObject);var  ATab: TTabSheet;begin  (** Page controls can act as owners, but not as parents:  SpeedBtn := TSpeedButton.Create(PageControl1); {This is OK, but ...}  SpeedBtn.Parent := PageControl1; {<-- Exception raised here!!!}  **)  { This will work perfectly ... }  ATab := PageControl1.AddTabSheet;  SpeedBtn := TSpeedButton.Create(ATab);  SpeedBtn.Parent := ATab;  (**)  { extra stuff from here on ...     look into the source :) }end; ETA: Quote from: nadavvin on December 20, 2018, 11:04:58 pmIt is a button to add a tab and have hint and custom on click event. I still get the error when I set it: PageControlMain.ControlStyle:=[csAcceptsControls];   FBtnAddTab.Parent := PageControlMain; Page controls reject any child other than (descendants of) TCustomPage*, so either you place the button outside the page control or you create a less "exclusive" page control. Of course there is an option (in TPageControl.Options) to show an "Add tab" button, but I infer this is too limited for you ... and it doesn't work always. Notes: * Depends on the widgetset, too, but I've yet to see one which accepts them. ---------------------------------------------------------------------- jamie · 2018-12-21 01:58 Ok, but for a windows target I wonder if using Windows.SetParent(PageControl.Hanlde, ChildControl.Handle); I see the speedbutton does not have a TwinControl Ok so no problem, place a Tpanel there and place the speedbutton in it.. Set all the auto sizing thingies to make it stay with the control.. ---------------------------------------------------------------------- lucamar · 2018-12-21 02:28 Quote from: jamie on December 21, 2018, 02:58:48 amOk, but for a windows target I wonder if using Windows.SetParent(PageControl.Hanlde, ChildControl.Handle); I see the speedbutton does not have a TwinControl Ok so no problem, place a Tpanel there and place the speedbutton in it.. Set all the auto sizing thingies to make it stay with the control.. You can try (and if you do, please tell us the result!) but I seriously doubt it would be as easy as that. I tried once something similar with Delphi, embedding some other control into a bare PageControl, and had to throw the towel. ---------------------------------------------------------------------- jamie · 2018-12-21 02:47 I just did it I dropped a Tpanel on the control and speedbutton inside it otherwise it hides behind the page control  I am doing this on a windows target with 1..8.4 if that make any difference...  unless I am doing something different... it seems to work. ---------------------------------------------------------------------- wp · 2018-12-21 08:32 Quote from: jamie on December 21, 2018, 03:47:48 amI dropped a Tpanel on the control and speedbutton inside it otherwise it hides behind the page control Are you sure that the panel is a child of the pagecontrol? Look at the object tree in the object inspector. Or: drag the pagecontrol to another location - the panel must follow if it is a child of the pagecontrol. ---------------------------------------------------------------------- lucamar · 2018-12-21 13:31 Jamie, to be double sure do it in code. Create a TPanel (any owner except nil) and try to make MyPanel.Parent:= MyPageControl; Like in my previous code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormCreate(Sender: TObject);begin  APanel := TPanel.Create(PageControl1);  APanel.Parent := PageControl1;  APanel.Caption := 'Am I under (page) control?';end; In my Linux machines it raises the same exception in the same place. ---------------------------------------------------------------------- jamie · 2018-12-21 22:09 Windows.SetParent(Panel1.Handle,PageCOntrol1.Handle);    The Panel is now a child of page control.. I placed a button on the form which when clicked, moves the PageControl.Left over 100 pixels.. The Panel goes with it. I have not done this using the LCL code but it works here with the windows target. The speedButton needs to be in a Tpanel of course and then place that panel on the pagecontrol There could be something in the LCL limited the use of it, I have not checked. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormCreate(Sender: TObject);begin  Windows.SetParent(Panel1.Handle,PageCOntrol1.Handle);end; ---------------------------------------------------------------------- lucamar · 2018-12-21 22:30 So it kind of can be made to work in Windows. Thanks, jamie. A pity that the OP isn't (I think*) using Windows. * Inferred from the window decoration, mostly ---------------------------------------------------------------------- jamie · 2018-12-21 22:44 Actually the SetParet exist in the LCLIntF.SetParent and that also works too.. The only issue with doing it this way is it does not get placed in the list of COntrols of the PageControl but I believe you can also force It in the list.. ---------------------------------------------------------------------- lucamar · 2018-12-21 23:04 Quote from: jamie on December 21, 2018, 11:44:23 pmActually the SetParet exist in the LCLIntF.SetParent and that also works too.. The only issue with doing it this way is it does not get placed in the list of COntrols of the PageControl but I believe you can also force It in the list.. I'll test it tomorrow in the Linux boxes. Sounds like a terrible kluge but it's a nice one to know.