Da 0wner
03-25-2008, 11:05 PM
Today we will be learning tabs. First of all if you don't know how to make a basic form please refer to my signature and click that link.
Don't forget to
http://i29.tinypic.com/14bksna.jpg
Rep me and rate excellent! :spot:
So if you want an example of tabs run this and click the buttons. They each write in the debug box.
Program New;
Var
frmDesign : TForm;
PageControl : TPageControl;
TabPages : array [1..3] of TTabSheet;
Button1 : TButton;
Button2 : TButton;
Button3 : TButton;
Procedure Click1(Sender : TObject);
Begin
writeln('You clicked the first button.');
End;
Procedure Click2(Sender : TObject);
Begin
writeln('You clicked the second button.');
End;
Procedure Click3(Sender : TObject);
Begin
writeln('You clicked the third button.');
End;
Procedure InitForm;
Var
i : integer;
Begin
frmDesign := CreateForm;
frmDesign.Left := 250;
frmDesign.Top := 114;
frmDesign.Width := 159;
frmDesign.Height := 100;
frmDesign.Caption := 'frmDesign';
frmDesign.Color := clBtnFace;
frmDesign.Font.Color := clWindowText;
frmDesign.Font.Height := -11;
frmDesign.Font.Name := 'MS Sans Serif';
frmDesign.Font.Style := [];
frmDesign.Visible := False;
frmDesign.PixelsPerInch := 96;
PageControl := TPageControl.Create(frmDesign);
PageControl.Parent := frmDesign;
PageControl.Align := alClient;
For i := 1 to 3 do
Begin
TabPages[i] := TTabSheet.Create(frmDesign);
TabPages[i].PageControl := PageControl;
End;
TabPages[1].Caption := 'Da';
TabPages[2].Caption := '0wner';
TabPages[3].Caption := 'Pwnz';
Button1 := TButton.Create(frmDesign);
Button1.Parent := TabPages[1];
Button1.Left := 25;
Button1.Top := 10;
Button1.Width := 90;
Button1.Height := 20;
Button1.Caption := 'This is on tab 1';
Button1.TabOrder := 8;
Button1.OnClick := @Click1;
Button2 := TButton.Create(frmDesign);
Button2.Parent := TabPages[2];
Button2.Left := 25;
Button2.Top := 10;
Button2.Width := 90;
Button2.Caption := 'This is on tab 2';
Button2.Height := 20;
Button2.TabOrder := 8;
Button2.OnClick := @Click2;
Button3 := TButton.Create(frmDesign);
Button3.Parent := TabPages[3];
Button3.Left := 25;
Button3.Top := 10;
Button3.Width := 90;
Button3.Caption := 'This is on tab 3';
Button3.Height := 20;
Button3.TabOrder := 8;
Button3.OnClick := @Click3;
End;
Procedure SafeInitForm;
Var
v: TVariantArray;
Begin
setarraylength(V, 0);
ThreadSafeCall('InitForm', v);
End;
Procedure ShowFormModal;
Begin
frmDesign.ShowModal;
End;
Procedure SafeShowFormModal;
Var
v: TVariantArray;
Begin
setarraylength(V, 0);
ThreadSafeCall('ShowFormModal', v);
End;
Begin
SafeInitForm;
SafeShowFormModal;
End.
Now if you are asking "how can i do that?" i'll explain here.
If you see
PageControl.Align := alClient;
That just aligns the Tabcontrol to the FrmDesign.
If you look at the var section you see this
PageControl : TPageControl;
TabPages : array [1..3] of TTabSheet;
Page control is the part where you are able to click the tabs.
TabPages are the pages you can click. I have 3 tabs on this so it's array [0..3]
If you look in the initform you see this
For i := 1 to 3 do
Begin
TabPages[i] := TTabSheet.Create(frmDesign);
TabPages[i].PageControl := PageControl;
End;
TabPages[1].Caption := 'Da';
TabPages[2].Caption := '0wner';
TabPages[3].Caption := 'Pwnz';
The for loop just creates all the tab pages and makes pagecontrol the parent. The captions after adds all the captions to the tabs.
To make the buttons etc. on different tabs all you have to do is
change
ButtonX.Parent := FrmDesign;
to
ButtonX.Parent := TabPages[x];
Change ButtonX to your component and TabPages to your TTabSheet var. And x to the tab you want. Remember the array starts at at 1!
That's it. If you have any additional questions please post them or PM me and i will answer.
Don't forget to
http://i29.tinypic.com/14bksna.jpg
Rep me and rate excellent! :spot:
So if you want an example of tabs run this and click the buttons. They each write in the debug box.
Program New;
Var
frmDesign : TForm;
PageControl : TPageControl;
TabPages : array [1..3] of TTabSheet;
Button1 : TButton;
Button2 : TButton;
Button3 : TButton;
Procedure Click1(Sender : TObject);
Begin
writeln('You clicked the first button.');
End;
Procedure Click2(Sender : TObject);
Begin
writeln('You clicked the second button.');
End;
Procedure Click3(Sender : TObject);
Begin
writeln('You clicked the third button.');
End;
Procedure InitForm;
Var
i : integer;
Begin
frmDesign := CreateForm;
frmDesign.Left := 250;
frmDesign.Top := 114;
frmDesign.Width := 159;
frmDesign.Height := 100;
frmDesign.Caption := 'frmDesign';
frmDesign.Color := clBtnFace;
frmDesign.Font.Color := clWindowText;
frmDesign.Font.Height := -11;
frmDesign.Font.Name := 'MS Sans Serif';
frmDesign.Font.Style := [];
frmDesign.Visible := False;
frmDesign.PixelsPerInch := 96;
PageControl := TPageControl.Create(frmDesign);
PageControl.Parent := frmDesign;
PageControl.Align := alClient;
For i := 1 to 3 do
Begin
TabPages[i] := TTabSheet.Create(frmDesign);
TabPages[i].PageControl := PageControl;
End;
TabPages[1].Caption := 'Da';
TabPages[2].Caption := '0wner';
TabPages[3].Caption := 'Pwnz';
Button1 := TButton.Create(frmDesign);
Button1.Parent := TabPages[1];
Button1.Left := 25;
Button1.Top := 10;
Button1.Width := 90;
Button1.Height := 20;
Button1.Caption := 'This is on tab 1';
Button1.TabOrder := 8;
Button1.OnClick := @Click1;
Button2 := TButton.Create(frmDesign);
Button2.Parent := TabPages[2];
Button2.Left := 25;
Button2.Top := 10;
Button2.Width := 90;
Button2.Caption := 'This is on tab 2';
Button2.Height := 20;
Button2.TabOrder := 8;
Button2.OnClick := @Click2;
Button3 := TButton.Create(frmDesign);
Button3.Parent := TabPages[3];
Button3.Left := 25;
Button3.Top := 10;
Button3.Width := 90;
Button3.Caption := 'This is on tab 3';
Button3.Height := 20;
Button3.TabOrder := 8;
Button3.OnClick := @Click3;
End;
Procedure SafeInitForm;
Var
v: TVariantArray;
Begin
setarraylength(V, 0);
ThreadSafeCall('InitForm', v);
End;
Procedure ShowFormModal;
Begin
frmDesign.ShowModal;
End;
Procedure SafeShowFormModal;
Var
v: TVariantArray;
Begin
setarraylength(V, 0);
ThreadSafeCall('ShowFormModal', v);
End;
Begin
SafeInitForm;
SafeShowFormModal;
End.
Now if you are asking "how can i do that?" i'll explain here.
If you see
PageControl.Align := alClient;
That just aligns the Tabcontrol to the FrmDesign.
If you look at the var section you see this
PageControl : TPageControl;
TabPages : array [1..3] of TTabSheet;
Page control is the part where you are able to click the tabs.
TabPages are the pages you can click. I have 3 tabs on this so it's array [0..3]
If you look in the initform you see this
For i := 1 to 3 do
Begin
TabPages[i] := TTabSheet.Create(frmDesign);
TabPages[i].PageControl := PageControl;
End;
TabPages[1].Caption := 'Da';
TabPages[2].Caption := '0wner';
TabPages[3].Caption := 'Pwnz';
The for loop just creates all the tab pages and makes pagecontrol the parent. The captions after adds all the captions to the tabs.
To make the buttons etc. on different tabs all you have to do is
change
ButtonX.Parent := FrmDesign;
to
ButtonX.Parent := TabPages[x];
Change ButtonX to your component and TabPages to your TTabSheet var. And x to the tab you want. Remember the array starts at at 1!
That's it. If you have any additional questions please post them or PM me and i will answer.