TNotebook: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: TNotebook
| Old | New | Line | |
|---|---|---|---|
| 1 | + |  **TNoteBook** is a component that provides a container to hold a variety of controls arranged in pages, much like a real-world notebook. It is a descendant of [[TWinControl]] and is available under the [[Additional tab]] of the [[Component Palette]]. | |
| 2 | + | ||
| 3 | + | ## Navigating from page to page | |
| 4 | + | ||
| 5 | + | All pages of the `TNotebook` are listed by the `Pages` property, a `TStrings` class which contains the page names. There is also a property `Page` (note the singular!) which lists the `TPage` controls into which other controls can be inserted. | |
| 6 | + | ||
| 7 | + | Unlike [[TPageControl]] the `TNotebook` does not have tabs. Therefore, navigation between pages is not as easy as with `TPageControl`: | |
| 8 | + | ||
| 9 | + | - At designtime the pages are listed in the object tree of the Object Inspector under the Notebook node; here the developer can easily switch from page to page. | |
| 10 | + | - At runtime, special code must be provided to show a specific page; the `PageIndex` property determines which page is currently visible. Here is an example for application of `TNotebook` in a tabless, wizard-like form with "Forward"/"Backward" buttons to move from page to page: | |
| 11 | + | ||
| 12 | + | ``` Pascal | |
| 13 | + | procedure TForm1.ForwardBtnClick(Sender: TObject); | |
| 14 | + | begin | |
| 15 | + | if Notebook1.PageIndex < Notebook1.PageCount-1 then | |
| 16 | + | Notebook1.PageIndex := Notebook1.PageIndex + 1; | |
| 17 | + | end; | |
| 18 | + | ||
| 19 | + | procedure TForm1.BackwardBtnClick(Sender: TObject); | |
| 20 | + | begin | |
| 21 | + | if Notebook1.PageIndex > 0 then | |
| 22 | + | Notebook1.PageIndex := Notebook1.PageIndex - 1; | |
| 23 | + | end; | |
| 24 | + | ``` | |
| 25 | + | ||
| 26 | + | ## Adding pages | |
| 27 | + | ||
| 28 | + | Pages can be added at designtime by right-clicking on the `TNotebook` component and selecting *Add Page* from the context menu. | |
| 29 | + | ||
| 30 | + | At runtime, a page is added by calling `Notebook.Add('new pagename')` with the name of the new page as parameter; the function returns the index of the new page. As already noted, the new page itself can be addressed by using the property `Notebook.Page[newindex]` (note the singular). The following example adds a new page and puts a `TMemo` on it: | |
| 31 | + | ||
| 32 | + | ``` Pascal | |
| 33 | + | procedure TForm1.NewPageBtnClick(Sender: TObject); | |
| 34 | + | var | |
| 35 | + | newIndex: Integer; | |
| 36 | + | begin | |
| 37 | + | newIndex := Notebook1.Pages.Add('New Page'); // use plural! | |
| 38 | + | with TMemo.Create(self) do | |
| 39 | + | begin | |
| 40 | + | Parent := Notebook1.Page[newIndex]; // use singular! | |
| 41 | + | Align := alClient; | |
| 42 | + | end; | |
| 43 | + | end; | |
| 44 | + | ``` | |
| 45 | + | ||
| 46 | + | ## Removing pages | |
| 47 | + | ||
| 48 | + | At designtime, a page can be removed by using the context menu of the `TNotebook` and selecting the menu item *Delete Page*. | |
| 49 | + | ||
| 50 | + | At runtime, a page is removed by deleting the corresponding index from the `Pages` list (plural!), or by destroying the `Page[index]` (singular!) at the specific index | |
| 51 | + | ||
| 52 | + | ``` Pascal | |
| 53 | + | procedure TForm1.DeleteCurrPageBtn(Sender: TObject); | |
| 54 | + | begin | |
| 55 | + | if Notebook1.PageIndex > -1 then | |
| 56 | + | Notebook1.Pages.Delete(Notebook1.PageIndex); | |
| 57 | + | // or: Notebook1.Page[Notebook1.PageIndex].Free | |
| 58 | + | end; | |
| 59 | + | end; | |
| 60 | + | ``` | |
| 61 | + | ||
| 62 | + | ## Similar controls | |
| 63 | + | ||
| 64 | + | - [[TPageControl]] | |
| 65 | + | - [[TTabControl]] | |
| 66 | + | ||
| 67 | + | ## See also | |
| 68 | + | ||
| 69 | + | - [[doc:lcl/extctrls/tnotebook.html|TNoteBook doc]] | |
| 70 | + | - [[doc:lcl/extctrls/multi-pagecontrols.html|Multi-page controls doc]] | |
| 71 | + | ||
| 72 | + | --- | |
| 73 | + | *From the Free Pascal wiki, page "TNotebook", as it stood on 2021-02-06 after a change by Wp, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
