1{ $Id$ } 2{ 3 /*************************************************************************** 4 NoteBookTest.pp 5 ------------------- 6 7 8 9 10 ***************************************************************************/ 11 12 *************************************************************************** 13 * * 14 * This source is free software; you can redistribute it and/or modify * 15 * it under the terms of the GNU General Public License as published by * 16 * the Free Software Foundation; either version 2 of the License, or * 17 * (at your option) any later version. * 18 * * 19 * This code is distributed in the hope that it will be useful, but * 20 * WITHOUT ANY WARRANTY; without even the implied warranty of * 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 22 * General Public License for more details. * 23 * * 24 * A copy of the GNU General Public License is available on the World * 25 * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also * 26 * obtain it by writing to the Free Software Foundation, * 27 * Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA. * 28 * * 29 *************************************************************************** 30} 31{ 32@abstract(An example application for TNotebook) 33@author(NoteBookTest.pp - Marc Weustink <weus@quicknet.nl>) 34} 35program NotebookTest; 36 37{$mode objfpc}{$H+} 38 39uses 40 Interfaces, Classes, Controls, Forms, Buttons, SysUtils, StdCtrls, 41 Graphics, ExtCtrls, LclProc; 42 43type 44 45 TForm1 = class(TForm) 46 Notebook1 : TNotebook; 47 Button1: TButton; 48 Button2: TButton; 49 Button3: TButton; 50 Label1: TLabel; 51 procedure Button1CLick(Sender : TObject); 52 procedure Button2CLick(Sender : TObject); 53 procedure Button3CLick(Sender : TObject); 54 public 55 constructor Create(AOwner: TComponent); override; 56 end; 57 58 59constructor TForm1.Create(AOwner: TComponent); 60begin 61 inherited CreateNew(AOwner, 1); 62 Caption := 'Notebook testing'; 63 Left := 0; 64 Top := 0; 65 Width := 700; 66 Height := 300; 67 Position:= poMainFormCenter; 68 69 Button1 := TButton.Create(Self); 70 with Button1 do begin 71 Top:= 0; 72 Left:= 0; 73 AutoSize := true; 74 Parent:= Self; 75 Caption := 'Create page'; 76 OnClick := @Button1Click; 77 end; 78 79 Button2 := TButton.Create(Self); 80 with Button2 do begin 81 AnchorSide[akLeft].Side := asrRight; 82 AnchorSide[akLeft].Control := Button1; 83 AnchorSide[akTop].Side := asrCenter; 84 AnchorSide[akTop].Control := Button1; 85 AutoSize := true; 86 Parent:= Self; 87 Caption := 'Back'; 88 OnClick := @Button2Click; 89 end; 90 91 Button3 := TButton.Create(Self); 92 with Button3 do begin 93 AnchorSide[akLeft].Side := asrRight; 94 AnchorSide[akLeft].Control := Button2; 95 AnchorSide[akTop].Side := asrCenter; 96 AnchorSide[akTop].Control := Button2; 97 AutoSize := true; 98 Parent:= Self; 99 Caption := 'Forward'; 100 OnClick := @Button3Click; 101 end; 102 103 Label1 := TLabel.Create(Self); 104 with Label1 do begin 105 AnchorSide[akLeft].Side := asrRight; 106 BorderSpacing.Left := 6; 107 AnchorSide[akLeft].Control := Button3; 108 AnchorSide[akTop].Side := asrCenter; 109 AnchorSide[akTop].Control := Button3; 110 Parent:= Self; 111 Caption := '0 pages total'; 112 end; 113 114 NoteBook1 := TNoteBook.Create(Self); 115 with NoteBook1 do 116 begin 117 AnchorSide[akTop].Side := asrBottom; 118 AnchorSide[akTop].Control := Button1; 119 Align := alBottom; 120 Anchors := Anchors + [akTop]; 121 Parent:= Self; 122 end; 123end; 124 125procedure TForm1.Button1Click(Sender : TObject); 126var 127 NewPageIndex: integer; 128 NewPage: TPage; 129 PageLabel: TLabel; 130begin 131 NewPageIndex := Notebook1.Pages.Add(Format('[Page %d]', [Notebook1.Pages.Count])); 132 NewPage := Notebook1.Page[NewPageIndex]; 133 PageLabel := TLabel.Create(Self); 134 with PageLabel do 135 begin 136 Left := 20; 137 Top := 10 + NewPageIndex * 20; 138 Width := 500; 139 Height := 20; 140 Caption := Format('This is page [%d]',[NewPageIndex]); 141 Parent := NewPage; 142 end; 143 Label1.Caption := IntToStr(Notebook1.PageCount)+ ' pages total'; 144end; 145 146procedure TForm1.Button2Click(Sender : TObject); 147begin 148 if Notebook1.PageIndex>0 then 149 Notebook1.PageIndex:=Notebook1.PageIndex-1; 150end; 151 152procedure TForm1.Button3Click(Sender : TObject); 153begin 154 if Notebook1.PageIndex<Notebook1.PageCount-1 then 155 Notebook1.PageIndex:=Notebook1.PageIndex+1; 156end; 157 158var 159 F1: TForm1; 160 161begin 162 DebugLN('------ INIT ------- '); 163 Application.Initialize; 164 DebugLN('------ CREATE ------- '); 165 Application.CreateForm(TForm1, F1); 166 DebugLN('------ RUN ------- '); 167 Application.Run; 168 DebugLN('------ DONE ------- '); 169end. 170