Recent

Author Topic: [SOLVED] TPageControl: Clearing it in one go?  (Read 9488 times)

EganSolo

  • Sr. Member
  • ****
  • Posts: 324
[SOLVED] TPageControl: Clearing it in one go?
« on: July 02, 2021, 06:59:33 pm »
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?


« Last Edit: July 03, 2021, 02:47:07 am by EganSolo »

dsiders

  • Hero Member
  • *****
  • Posts: 1431
Re: TPageControl: Clearing it in one go?
« Reply #1 on: July 02, 2021, 08:20:31 pm »
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?

Interesting. Like you said... brute force:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var iPos: Integer;
  3. begin
  4.   iPos := PageControl1.PageCount-1;
  5.   while iPos >= 0 do
  6.   begin
  7.     PageControl1.Page[iPos].Free;
  8.     Dec(iPos);
  9.   end;
  10. end;

At some point the multi-page controls were refactored. But that's a curious omission. File a bug report.

Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

wp

  • Hero Member
  • *****
  • Posts: 12864
Re: TPageControl: Clearing it in one go?
« Reply #2 on: July 02, 2021, 09:04:56 pm »
This is a simpler one, but more hacky:
Code: Pascal  [Select][+][-]
  1. type  // before Form1 declaration!
  2.   TPageControl = class(ComCtrls.TPageControl)
  3.   public
  4.     property Tabs;
  5.   end;
  6.  
  7.   TForm1 = class(TForm)
  8.     PageControl1: TPageControl;
  9.   ...
  10.  
  11. procedure TForm1.Button1Click(Sender: TObject);
  12. begin
  13.   PageControl1.Tabs.Clear;
  14. end;

dsiders

  • Hero Member
  • *****
  • Posts: 1431
Re: TPageControl: Clearing it in one go?
« Reply #3 on: July 02, 2021, 11:23:45 pm »
This is a simpler one, but more hacky:
Code: Pascal  [Select][+][-]
  1. type  // before Form1 declaration!
  2.   TPageControl = class(ComCtrls.TPageControl)
  3.   public
  4.     property Tabs;
  5.   end;
  6.  
  7.   TForm1 = class(TForm)
  8.     PageControl1: TPageControl;
  9.   ...
  10.  
  11. procedure TForm1.Button1Click(Sender: TObject);
  12. begin
  13.   PageControl1.Tabs.Clear;
  14. end;

Interposer. I don't consider that hacky. ;)
Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

EganSolo

  • Sr. Member
  • ****
  • Posts: 324
[SOLVED] Re: TPageControl: Clearing it in one go?
« Reply #4 on: July 03, 2021, 02:46:47 am »
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][+][-]
  1.     type  // before Form1 declaration!
  2.       TPageControl = class(ComCtrls.TPageControl)
  3.       public
  4.         property Tabs;
  5.       end;
  6.      
  7.       TForm1 = class(TForm)
  8.         PageControl1: TPageControl;
  9.       ...
  10.      
  11.     procedure TForm1.Button1Click(Sender: TObject);
  12.     begin
  13.       PageControl1.Tabs.Clear;
  14.     end;
  15.  

screaming for an update of TPageControl to include a clear method?



dsiders

  • Hero Member
  • *****
  • Posts: 1431
Re: [SOLVED] Re: TPageControl: Clearing it in one go?
« Reply #5 on: July 03, 2021, 03:26:37 am »
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][+][-]
  1.     type  // before Form1 declaration!
  2.       TPageControl = class(ComCtrls.TPageControl)
  3.       public
  4.         property Tabs;
  5.       end;
  6.      
  7.       TForm1 = class(TForm)
  8.         PageControl1: TPageControl;
  9.       ...
  10.      
  11.     procedure TForm1.Button1Click(Sender: TObject);
  12.     begin
  13.       PageControl1.Tabs.Clear;
  14.     end;
  15.  

screaming for an update of TPageControl to include a clear method?

That's why I suggested a bug report.
Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

wp

  • Hero Member
  • *****
  • Posts: 12864
Re: [SOLVED] TPageControl: Clearing it in one go?
« Reply #6 on: July 03, 2021, 10:45:05 pm »
In r65355, I added a new method TPageControl.Clear.

Muso

  • Sr. Member
  • ****
  • Posts: 357
Re: [SOLVED] TPageControl: Clearing it in one go?
« Reply #7 on: July 04, 2021, 03:45:21 pm »
In 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

  • Hero Member
  • *****
  • Posts: 1431
Re: [SOLVED] TPageControl: Clearing it in one go?
« Reply #8 on: July 04, 2021, 04:15:19 pm »
In 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.
Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

Muso

  • Sr. Member
  • ****
  • Posts: 357
Re: [SOLVED] TPageControl: Clearing it in one go?
« Reply #9 on: July 04, 2021, 04:31:12 pm »
It was added to TPageControl documentation in r65358.

But that is the commit:
https://github.com/graemeg/lazarus/commit/88f4df3a9faea24bf1f5963a8edcf98af74d0756

and there is no change to XML files etc.

dsiders

  • Hero Member
  • *****
  • Posts: 1431
« Last Edit: July 04, 2021, 04:57:50 pm by dsiders »
Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

wp

  • Hero Member
  • *****
  • Posts: 12864
Re: [SOLVED] TPageControl: Clearing it in one go?
« Reply #11 on: July 04, 2021, 05:06:58 pm »
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

  • Hero Member
  • *****
  • Posts: 1431
Re: [SOLVED] TPageControl: Clearing it in one go?
« Reply #12 on: July 04, 2021, 05:34:45 pm »
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).

No problem. I just pointed out the duplicate.

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...

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.
« Last Edit: July 04, 2021, 06:15:45 pm by dsiders »
Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

wp

  • Hero Member
  • *****
  • Posts: 12864
Re: [SOLVED] TPageControl: Clearing it in one go?
« Reply #13 on: July 05, 2021, 08:46:06 pm »
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

  • Hero Member
  • *****
  • Posts: 1431
Re: [SOLVED] TPageControl: Clearing it in one go?
« Reply #14 on: July 06, 2021, 06:14:33 am »
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.

@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.
Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

 

TinyPortal © 2005-2018