PDA

View Full Version : [TUT] Tabs on Forms [/TUT]



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.

Cazax
03-25-2008, 11:08 PM
I have been waiting for one, thanks.

Da 0wner
03-26-2008, 02:21 AM
So caz did you read? :p If you did post what forms you made with this tut.

skilld u
03-26-2008, 02:25 AM
im working on a form right now to test this. will post in a minute. :p

program New;

var
frmDesign : TForm;
Label1 : TLabel;
Button1, Button2, Button5 : TButton;
PageControl : TPageControl;
TabPages : array [1..3] of TTabSheet;
i : integer;

Procedure Click1(Sender : TObject);
Begin

writeln('Maybe...');
writeln('nope, try again :p');

End;

Procedure Click2(Sender : TObject);
Begin

frmDesign.ModalResult:= mrOk;

End;

Procedure Click3(Sender : TObject);
Begin

writeln('Not this button.');

End;

procedure FormStuff;
begin
frmDesign := CreateForm;
frmDesign.Left := 267;
frmDesign.Top := 114;
frmDesign.Width := 192;
frmDesign.Height := 124;
frmDesign.Caption := 'skilld u';
frmDesign.Color := clCoral;
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 := 'skilld u';
TabPages[2].Caption := 'pwnz';
TabPages[3].Caption := 'Da 0wner :p';

Label1 := TLabel.Create(frmDesign);
Label1.Parent := frmDesign;
Label1.Left := 32;
Label1.Top := 16;
Label1.Width := 119;
Label1.Height := 16;
Label1.Caption := 'Skilld U pwnz Formz';
Label1.Font.Color := clWindowText;
Label1.Font.Height := -15;
Label1.Font.Name := 'MS Sans Serif';
Label1.Font.Style := [];
Label1.ParentFont := False;
Button1 := TButton.Create(frmDesign);
Button1.Parent := TabPages[1];
Button1.Left := 60;
Button1.Top := 15;
Button1.Width := 65;
Button1.Height := 17;
Button1.Caption := 'maybe';
Button1.TabOrder := 8;
Button1.OnClick := @Click1;

Button2 := TButton.Create(frmDesign);
Button2.Parent := TabPages[2];
Button2.Left := 60;
Button2.Top := 15;
Button2.Width := 65;
Button2.Height := 17;
Button2.Caption := 'maybe';
Button2.TabOrder := 8;
Button2.OnClick := @Click2;

Button5 := TButton.Create(frmDesign);
Button5.Parent := TabPages[3];
Button5.Left := 60;
Button5.Top := 15;
Button5.Width := 65;
Button5.Height := 17;
Button5.Caption := 'maybe';
Button5.TabOrder := 8;
Button5.OnClick := @Click3;
end;

procedure ShowForm;
var
v: TVariantArray;
begin
setarraylength(V, 0);
ThreadSafeCall('FormStuff', v);
end;

procedure ShowformModal;
begin
frmDesign.ShowModal;
end;

procedure SafeShowModal;
var
v: TVariantArray;
begin
setarraylength(V, 0);
ThreadSafeCall('ShowformModal', v);
end;

begin
ShowForm;
SafeShowModal;
end.

BobboHobbo
03-26-2008, 02:38 AM
Forms at beginers and neither is tabs lol, but its still easy.

EvilChicken!
03-26-2008, 05:12 AM
Forms at beginers and neither is tabs lol, but its still easy.

Well, at least its a pretty good tut, thanks!
I'll try this later along with your INI tut. THNAKS!

Richard
03-29-2008, 10:05 PM
Dude seriously, apply for members just with a script thats a form. You could be the writer of the next SRL player form.

EDIT: I made one, I took it from my fletcher if you are wondering why the weird things:


Program KoolForm;

var
frmDesign : TForm;
GroupBox1 : TGroupBox;
CheckBox1 : TCheckBox;
Edit1 : TEdit;
Edit2 : TEdit;
Edit3 : TEdit;
Edit4 : TEdit;
Edit5 : TEdit;
Button1 : TButton;
Edit6 : TEdit;
Edit7 : TEdit;
Edit8 : TEdit;
Edit9 : TEdit;
PageControl : TPageControl;
TabPages : array [1..3] of TTabSheet;
i : integer;

////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////

procedure StartClick(sender: TObject);
begin
frmDesign.ModalResult:= mrOk;
end;

////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////

Procedure Form;
Begin

frmDesign := CreateForm;
frmDesign.Left := 250;
frmDesign.Top := 173;
frmDesign.Width := 361;
frmDesign.Height := 287;
frmDesign.Caption := 'Any Longbow Maker';
frmDesign.Color := clMaroon;
frmDesign.Font.Color := clRed;
frmDesign.Font.Height := -11;
frmDesign.Font.Name := 'Comic Sans MS';
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 := 'dude richard';
TabPages[2].Caption := 'is better than';
TabPages[3].Caption := 'Da 0wner ';
GroupBox1 := TGroupBox.Create(frmDesign);
GroupBox1.Parent := frmDesign;
GroupBox1.Left := 0;
GroupBox1.Top := 20;
GroupBox1.Width := 353;
GroupBox1.Height := 233;
GroupBox1.Caption := 'DR'#39's any longbow maker setup';
GroupBox1.Font.Color := clRed;
GroupBox1.Font.Height := -11;
GroupBox1.Font.Name := 'Comic Sans MS';
GroupBox1.Font.Style := [];
GroupBox1.ParentFont := False;
GroupBox1.TabOrder := 0;
CheckBox1 := TCheckBox.Create(GroupBox1);
CheckBox1.Parent := GroupBox1;
CheckBox1.Left := 24;
CheckBox1.Top := 168;
CheckBox1.Width := 121;
CheckBox1.Height := 41;
CheckBox1.Caption := 'Use every 50 sleep?';
CheckBox1.Checked := True;
CheckBox1.State := cbChecked;
CheckBox1.TabOrder := 0;
Edit1 := TEdit.Create(GroupBox1);
Edit1.Parent := GroupBox1;
Edit1.Left := 144;
Edit1.Top := 40;
Edit1.Width := 73;
Edit1.Height := 23;
Edit1.TabOrder := 1;
Edit1.Text := 'Password';
Edit2 := TEdit.Create(GroupBox1);
Edit2.Parent := GroupBox1;
Edit2.Left := 24;
Edit2.Top := 40;
Edit2.Width := 73;
Edit2.Height := 23;
Edit2.TabOrder := 2;
Edit2.Text := 'Username';
Edit3 := TEdit.Create(GroupBox1);
Edit3.Parent := GroupBox1;
Edit3.Left := 24;
Edit3.Top := 80;
Edit3.Width := 73;
Edit3.Height := 23;
Edit3.TabOrder := 3;
Edit3.Text := 'PIN';
Edit4 := TEdit.Create(GroupBox1);
Edit4.Parent := GroupBox1;
Edit4.Left := 144;
Edit4.Top := 80;
Edit4.Width := 73;
Edit4.Height := 23;
Edit4.TabOrder := 4;
Edit4.Text := 'Nickname';
Edit5 := TEdit.Create(GroupBox1);
Edit5.Parent := GroupBox1;
Edit5.Left := 24;
Edit5.Top := 120;
Edit5.Width := 73;
Edit5.Height := 23;
Edit5.TabOrder := 5;
Edit5.Text := 'Loads';
Button1 := TButton.Create(GroupBox1);
Button1.Parent := GroupBox1;
Button1.Left := 176;
Button1.Top := 168;
Button1.Width := 145;
Button1.Height := 41;
Button1.Caption := 'Start Any Longbow Maker';
Button1.TabOrder := 6;
Button1.OnClick := @StartClick
Edit6 := TEdit.Create(GroupBox1);
Edit6.Parent := GroupBox1;
Edit6.Left := 144;
Edit6.Top := 120;
Edit6.Width := 73;
Edit6.Height := 23;
Edit6.TabOrder := 7;
Edit6.Text := 'Log type';
Edit7 := TEdit.Create(GroupBox1);
Edit7.Parent := GroupBox1;
Edit7.Left := 256;
Edit7.Top := 40;
Edit7.Width := 73;
Edit7.Height := 23;
Edit7.TabOrder := 8;
Edit7.Text := 'Which Bank';
Edit8 := TEdit.Create(GroupBox1);
Edit8.Parent := GroupBox1;
Edit8.Left := 256;
Edit8.Top := 80;
Edit8.Width := 73;
Edit8.Height := 23;
Edit8.TabOrder := 9;
Edit8.Text := 'Stats ID';
Edit9 := TEdit.Create(GroupBox1);
Edit9.Parent := GroupBox1;
Edit9.Left := 256;
Edit9.Top := 120;
Edit9.Width := 73;
Edit9.Height := 23;
Edit9.TabOrder := 10;
Edit9.Text := 'Stats Pass';
end;

////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////

procedure SafeInitForm;
var
v: TVariantArray;
begin
setarraylength(V, 0);
ThreadSafeCall('Form', 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.