[SOLVED] TPageControl: Clearing it in one go? lazarus / 31-LCL ---------------------------------------------------------------------- EganSolo · 2021-07-02 16:59 I looked for a TPageControl.Clear method but no dice. So what's the best way to implement a TPageControl clear method which would delete all the sheets in the page control? A brute-force way is to delete the page control itself and create a new one. A second method would iterate through all the pages and free them one by one. I did notice that in the TCustomTabControl has a public property called Pages which, presumably, holds a list of all the pages. Calling Pages.Clear would do the trick but TPageControl "hides" that property by defining Pages as an array property. Thoughts? ---------------------------------------------------------------------- dsiders · 2021-07-02 18:20 Quote from: EganSolo on July 02, 2021, 06:59:33 pmI looked for a TPageControl.Clear method but no dice. So what's the best way to implement a TPageControl clear method which would delete all the sheets in the page control? A brute-force way is to delete the page control itself and create a new one. A second method would iterate through all the pages and free them one by one. I did notice that in the TCustomTabControl has a public property called Pages which, presumably, holds a list of all the pages. Calling Pages.Clear would do the trick but TPageControl "hides" that property by defining Pages as an array property. Thoughts? Interesting. Like you said... brute force: 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.Button1Click(Sender: TObject);var iPos: Integer;begin  iPos := PageControl1.PageCount-1;  while iPos >= 0 do  begin    PageControl1.Page[iPos].Free;    Dec(iPos);  end;end; At some point the multi-page controls were refactored. But that's a curious omission. File a bug report. ---------------------------------------------------------------------- wp · 2021-07-02 19:04 This is a simpler one, but more hacky: 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 type  // before Form1 declaration!  TPageControl = class(ComCtrls.TPageControl)  public    property Tabs;  end;   TForm1 = class(TForm)    PageControl1: TPageControl;  ... procedure TForm1.Button1Click(Sender: TObject);begin  PageControl1.Tabs.Clear;end; ---------------------------------------------------------------------- dsiders · 2021-07-02 21:23 Quote from: wp on July 02, 2021, 09:04:56 pmThis is a simpler one, but more hacky: 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 type  // before Form1 declaration!  TPageControl = class(ComCtrls.TPageControl)  public    property Tabs;  end;   TForm1 = class(TForm)    PageControl1: TPageControl;  ... procedure TForm1.Button1Click(Sender: TObject);begin  PageControl1.Tabs.Clear;end; Interposer. I don't consider that hacky. ---------------------------------------------------------------------- EganSolo · 2021-07-03 00:46 Thank you for your comments. Very helpful. Hacky's solution solves my problem since I'm already deriving a class from TPageControl. Having said that, doesn't the code that Hacky provided: 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     type  // before Form1 declaration!      TPageControl = class(ComCtrls.TPageControl)      public        property Tabs;      end;           TForm1 = class(TForm)        PageControl1: TPageControl;      ...         procedure TForm1.Button1Click(Sender: TObject);    begin      PageControl1.Tabs.Clear;    end; screaming for an update of TPageControl to include a clear method? ---------------------------------------------------------------------- dsiders · 2021-07-03 01:26 Quote from: EganSolo on July 03, 2021, 02:46:47 amThank you for your comments. Very helpful. Hacky's solution solves my problem since I'm already deriving a class from TPageControl. Having said that, doesn't the code that Hacky provided: 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     type  // before Form1 declaration!      TPageControl = class(ComCtrls.TPageControl)      public        property Tabs;      end;           TForm1 = class(TForm)        PageControl1: TPageControl;      ...         procedure TForm1.Button1Click(Sender: TObject);    begin      PageControl1.Tabs.Clear;    end; screaming for an update of TPageControl to include a clear method? That's why I suggested a bug report. ---------------------------------------------------------------------- wp · 2021-07-03 20:45 In r65355, I added a new method TPageControl.Clear. ---------------------------------------------------------------------- Muso · 2021-07-04 13:45 Quote from: wp on July 03, 2021, 10:45:05 pmIn r65355, I added a new method TPageControl.Clear. Many thanks! A very useful feature. However, I cannot find yet any documentation. Sorry, if I might annoy you   , it is just that I know I will forget about this sooner or later. ---------------------------------------------------------------------- dsiders · 2021-07-04 14:15 Quote from: Muso on July 04, 2021, 03:45:21 pmQuote from: wp on July 03, 2021, 10:45:05 pmIn r65355, I added a new method TPageControl.Clear. Many thanks! A very useful feature. However, I cannot find yet any documentation. Sorry, if I might annoy you   , it is just that I know I will forget about this sooner or later. It was added to TPageControl documentation in r65358. Since updated docs come only with new releases, feel free to rebuild the chm or html locally. ---------------------------------------------------------------------- Muso · 2021-07-04 14:31 Quote from: dsiders on July 04, 2021, 04:15:19 pmIt was added to TPageControl documentation in r65358. But that is the commit: https://github.com/graemeg/lazarus/commit/88f4df3a9faea24bf1f5963a8edc f98af74d0756 and there is no change to XML files etc. ---------------------------------------------------------------------- dsiders · 2021-07-04 14:53 Quote from: Muso on July 04, 2021, 04:31:12 pmQuote from: dsiders on July 04, 2021, 04:15:19 pmIt was added to TPageControl documentation in r65358. But that is the commit: https://github.com/graemeg/lazarus/commit/88f4df3a9faea24bf1f5963a8edc f98af74d0756 and there is no change to XML files etc. https://github.com/graemeg/lazarus/commit/a04d17869c0e00a98115d49f0c82 adb5e536718f#diff- a3be243b5821edb7923418e0dc9a1c17722f7c21395f473584e7693f852796c5 So now its in there twice. ---------------------------------------------------------------------- wp · 2021-07-04 15:06 Sorry, dsiders, my trunk was not up-to-date when I added my version of the TPagecontrol.Clear doc. In the recent commit, I picked the "best" sentences from both versions and merged them together (feel free to change it again). I see that you nicely format your additions to the xml files. There may be a disappointing experience waiting for you. If someone like me uses the FPDoc Editor from the View menu to enter help text directly from the IDE, then all your nice formatting will be destroyed because the FPDoc Editor seems to have its own (strange) preferences of nice formatting. I remember that I had reported this and related issues on the mailing list (https://lists.lazarus- ide.org/pipermail/lazarus/2019-December/237423.html), but nobody seems to take care... ---------------------------------------------------------------------- dsiders · 2021-07-04 15:34 Quote from: wp on July 04, 2021, 05:06:58 pmSorry, dsiders, my trunk was not up-to-date when I added my version of the TPagecontrol.Clear doc. In the recent commit, I picked the "best" sentences from both versions and merged them together (feel free to change it again). No problem. I just pointed out the duplicate. Quote from: wp on July 04, 2021, 05:06:58 pmI see that you nicely format your additions to the xml files. There may be a disappointing experience waiting for you. If someone like me uses the FPDoc Editor from the View menu to enter help text directly from the IDE, then all your nice formatting will be destroyed because the FPDoc Editor seems to have its own (strange) preferences of nice formatting. I remember that I had reported this and related issues on the mailing list (https://lists.lazarus- ide.org/pipermail/lazarus/2019-December/237423.html), but nobody seems to take care... I wouldn't say nobody cares. I just read the mailing list message. I'll check for the duplicates issues in graphics.xml. As for the XML formatting, the whitespace and indenting are a natural by-product of my editor. I don't use the FPDoc editor. If the formatting gets changed by the FPDoc Editor later, so be it. I'm not obsessed about the XML formatting. [EDIT] r65367 fixes a duplicate enumeration value in TFontQuality. The other duplicates were handled at the time of the original discussion. ---------------------------------------------------------------------- wp · 2021-07-05 18:46 Off-topic: dsiders, do you know how an inherited xml text can be disabled? I am asking because I am writing the help text for the TChart method EraseBackground which is an empty procedure, and I want to have in the description that the inherited behaviour is ignored. But the help system always inserts the description inherited from TWinControl.EraseBackground in addition to mine which makes the popup help very confusing because it does not apply here. If you want to have a look: I just updated the TAChart xml help files in trunk. ---------------------------------------------------------------------- dsiders · 2021-07-06 04:14 Quote from: wp on July 05, 2021, 08:46:06 pmOff-topic: dsiders, do you know how an inherited xml text can be disabled? I am asking because I am writing the help text for the TChart method EraseBackground which is an empty procedure, and I want to have in the description that the inherited behaviour is ignored. But the help system always inserts the description inherited from TWinControl.EraseBackground in addition to mine which makes the popup help very confusing because it does not apply here. If you want to have a look: I just updated the TAChart xml help files in trunk. @wp: You're referring to the display in CodeHelp, right? It seems to always combine all help topics in the inheritance tree that have an XML file. I am not aware of any way to disable it or prevent it. It is a bit of a distraction. IMHO, it should only search ancestors if there is no content for the current symbol. That may be something that needs a little more exploration.