PageRenderTime 15ms CodeModel.GetById 6ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/taborder.pas

http://github.com/graemeg/lazarus
Pascal | 156 lines | 125 code | 26 blank | 5 comment | 4 complexity | 546259299c122826b87d911b2738e2a7 MD5 | raw file
  1program TabOrder;
  2
  3{$mode objfpc}{$H+}
  4
  5uses
  6  Interfaces, Classes, SysUtils, Forms, Controls, Buttons, StdCtrls, ExtCtrls,
  7  ComCtrls;
  8
  9type
 10
 11  { TForm1 }
 12
 13  TForm1 = class(TForm)
 14    PageCtrl: TPageControl;
 15    CloseButton: TButton;
 16    Edit1: TEdit;
 17    Edit2: TEdit;
 18    Label1: TLabel;
 19  public
 20    constructor Create(TheOwner: TComponent); override;
 21    procedure CloseButtonClick(Sender: TObject);
 22    procedure WriteTabOrder;
 23  end;
 24
 25{ TForm1 }
 26
 27constructor TForm1.Create(TheOwner: TComponent);
 28
 29  procedure CreatePage1;
 30  begin
 31    Label1:=TLabel.Create(Self);
 32    with Label1 do begin
 33      Name:='Label1';
 34      Parent:=PageCtrl.Page[0];
 35      SetBounds(10,10,250,Height);
 36      Caption:='TabOrder: First Edit below, then Edit above';
 37    end;
 38  
 39    Edit1:=TEdit.Create(Self);
 40    with Edit1 do begin
 41      Name:='Edit1';
 42      Parent:=PageCtrl.Page[0];
 43      SetBounds(10,40,100,Height);
 44    end;
 45
 46    Edit2:=TEdit.Create(Self);
 47    with Edit2 do begin
 48      Name:='Edit2';
 49      Parent:=PageCtrl.Page[0];
 50      SetBounds(10,70,100,Height);
 51    end;
 52    
 53    // define Taborder
 54    Edit2.TabStop:=true;
 55    Edit2.TabOrder:=0;
 56    Edit1.TabStop:=true;
 57    Edit1.TabOrder:=1;
 58  end;
 59
 60  procedure CreatePage2;
 61  begin
 62  end;
 63
 64  procedure CreatePage3;
 65  begin
 66  end;
 67
 68var
 69  i: integer;
 70begin
 71  inherited CreateNew(TheOwner, 1);
 72  Name:='Form1';
 73  Position:=poScreenCenter;
 74  SetInitialBounds(0,0,400,300);
 75  
 76  PageCtrl:=TPageControl.Create(Self);
 77  with PageCtrl do begin
 78    Name:='PageCtrl';
 79    Parent:=Self;
 80    Align:=alTop;
 81    Height:=Parent.ClientHeight-40;
 82    
 83    for i:=1 to 3 do
 84      with TTabSheet.Create(PageCtrl) do
 85      begin
 86        PageControl:=PageCtrl;
 87        Name:='Page'+IntToStr(i);
 88        Caption:=Name;
 89      end;
 90    Anchors:=[akLeft,akTop,akRight,akBottom];
 91    PageIndex:=0;
 92  end;
 93  
 94  CloseButton:=TButton.Create(Self);
 95  with CloseButton do begin
 96    Name:='CloseButton';
 97    Parent:=Self;
 98    Caption:='Close';
 99    Anchors:=[akRight,akBottom];
100    SetBounds(Parent.ClientWidth-110,Parent.ClientHeight-35,100,Height);
101    OnClick:=@CloseButtonClick;
102  end;
103  
104  CreatePage1;
105  CreatePage2;
106  CreatePage3;
107  
108  // define TabOrder
109  CloseButton.TabStop:=true;
110  CloseButton.TabOrder:=0;
111  PageCtrl.TabStop:=true;
112  PageCtrl.TabOrder:=1;
113  PageCtrl.Page[0].TabStop:=true;
114  PageCtrl.Page[0].TabOrder:=2;
115  PageCtrl.Page[1].TabStop:=true;
116  PageCtrl.Page[1].TabOrder:=3;
117  PageCtrl.Page[2].TabStop:=true;
118  PageCtrl.Page[2].TabOrder:=4;
119
120  WriteTabOrder;
121end;
122
123procedure TForm1.CloseButtonClick(Sender: TObject);
124begin
125  Close;
126end;
127
128procedure TForm1.WriteTabOrder;
129
130  procedure WriteTabOrderTree(const Prefix: string; AControl: TControl);
131  var
132    i: Integer;
133  begin
134    write(Prefix,AControl.Name);
135    if AControl is TWinControl then
136      write('  TabOrder=',TWinControl(AControl).TabOrder,
137            ' TabStop=',TWinControl(AControl).TabStop);
138    writeln('');
139    if AControl is TWinControl then
140      for i:=0 to TWinControl(AControl).ControlCount-1 do begin
141        WriteTabOrderTree(Prefix+'  ',TWinControl(AControl).Controls[i]);
142      end;
143  end;
144
145begin
146  WriteTabOrderTree('',Self);
147end;
148
149var
150  Form1: TForm1;
151begin
152  Application.Initialize;
153  Application.CreateForm(TForm1,Form1);
154  Application.Run;
155end.
156