File: taborder.pas

package info (click to toggle)
lazarus 0.9.28.2-12
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 93,096 kB
  • ctags: 89,312
  • sloc: pascal: 820,189; xml: 202,194; makefile: 110,323; sh: 2,460; perl: 395; sql: 174; ansic: 133
file content (155 lines) | stat: -rw-r--r-- 3,092 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
program TabOrder;

{$mode objfpc}{$H+}

uses
  Interfaces, Classes, SysUtils, Forms, Controls, Buttons, StdCtrls, ExtCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    NoteBook: TNotebook;
    Page1: TPage;
    Page2: TPage;
    Page3: TPage;
    CloseButton: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
  public
    constructor Create(TheOwner: TComponent); override;
    procedure WriteTabOrder;
  end;

{ TForm1 }

constructor TForm1.Create(TheOwner: TComponent);

  procedure CreatePage1;
  begin
    Label1:=TLabel.Create(Self);
    with Label1 do begin
      Name:='Label1';
      Parent:=Page1;
      SetBounds(10,10,250,Height);
      Caption:='TabOrder: First Edit below, then Edit above';
    end;
  
    Edit1:=TEdit.Create(Self);
    with Edit1 do begin
      Name:='Edit1';
      Parent:=Page1;
      SetBounds(10,40,100,Height);
    end;

    Edit2:=TEdit.Create(Self);
    with Edit2 do begin
      Name:='Edit2';
      Parent:=Page1;
      SetBounds(10,70,100,Height);
    end;
    
    // define Taborder
    Edit2.TabStop:=true;
    Edit2.TabOrder:=0;
    Edit1.TabStop:=true;
    Edit1.TabOrder:=1;
  end;

  procedure CreatePage2;
  begin
  end;

  procedure CreatePage3;
  begin
  end;

begin
  inherited Create(TheOwner);
  Name:='Form1';
  Position:=poScreenCenter;
  SetInitialBounds(0,0,400,300);
  
  NoteBook:=TNotebook.Create(Self);
  with NoteBook do begin
    Name:='NoteBook';
    Parent:=Self;
    Align:=alTop;
    Height:=Parent.ClientHeight-40;
    
    Pages.Add('Page1');
    Page1:=Page[0];
    Page1.Name:='Page1';
    
    Pages.Add('Page2');
    Page2:=Page[1];
    Page2.Name:='Page2';

    Pages.Add('Page3');
    Page3:=Page[2];
    Page3.Name:='Page3';

    Anchors:=[akLeft,akTop,akRight,akBottom];
    PageIndex:=0;
  end;
  
  CloseButton:=TButton.Create(Self);
  with CloseButton do begin
    Name:='CloseButton';
    Parent:=Self;
    Caption:='Close';
    Anchors:=[akRight,akBottom];
    SetBounds(Parent.ClientWidth-110,Parent.ClientHeight-35,100,Height);
    ModalResult:=mrCancel;
  end;
  
  CreatePage1;
  CreatePage2;
  CreatePage3;
  
  // define TabOrder
  CloseButton.TabStop:=true;
  CloseButton.TabOrder:=0;
  NoteBook.TabStop:=true;
  NoteBook.TabOrder:=1;
  Page1.TabStop:=true;
  Page1.TabOrder:=2;
  Page2.TabStop:=true;
  Page2.TabOrder:=3;
  Page3.TabStop:=true;
  Page3.TabOrder:=4;

  WriteTabOrder;
end;

procedure TForm1.WriteTabOrder;

  procedure WriteTabOrderTree(const Prefix: string; AControl: TControl);
  var
    i: Integer;
  begin
    write(Prefix,AControl.Name);
    if AControl is TWinControl then
      write('  TabOrder=',TWinControl(AControl).TabOrder,
            ' TabStop=',TWinControl(AControl).TabStop);
    writeln('');
    if AControl is TWinControl then
      for i:=0 to TWinControl(AControl).ControlCount-1 do begin
        WriteTabOrderTree(Prefix+'  ',TWinControl(AControl).Controls[i]);
      end;
  end;

begin
  WriteTabOrderTree('',Self);
end;

var
  Form1: TForm1;
begin
  Application.Initialize;
  Application.CreateForm(TForm1,Form1);
  Application.Run;
end.