SKy Scripter
2007-07-15 18:11:13
How To Add Tabs

In Order To Make Tabs You Must Have A PageControl
Secondly You Must Have Your TabPages
Now That You Know What Is Needed To Make Tabs Lets Start.
Will Start by declaring are Variables…
Next We Will make Are Form
Now That We Have Are Form Its Time to Put Are PageControl In!
Now That We Have Are PageControl in Lets Add Are Tabs!
EXTRAS (Sender's)
Using OnShow And OnHide
Make Tabs Switchable!!!
in order to switch the tab you must hold Ctrl while dragging it to the other tab.

In Order To Make Tabs You Must Have A PageControl
var
PageControl : TPageControl;
Secondly You Must Have Your TabPages
var
TabPages : array [1..2] of TTabSheet;
Now That You Know What Is Needed To Make Tabs Lets Start.
Will Start by declaring are Variables…
program AddingTabs;
// Adding variables
const
Amount = 10; // How Many Sheets
var
MainForm : TForm; // Are Main TForm
PageControl : TPageControl; // This is Are page Control Which controls are tabs
TabPages : array [1..Amount] of TTabSheet; // Array of 2 TTabSheet's (Which are Pages)
begin
end.Next We Will make Are Form
program AddingTabs;
// Adding Form :)
const
Amount = 10; // How Many Sheets
var
MainForm : TForm; // Are Main TForm
PageControl : TPageControl; // This is Are page Control Wich controls are tabs
TabPages : array [1..Amount] of TTabSheet;
procedure NotLoadForm;
begin
MainForm := CreateForm;
MainForm.SetBounds({left} 0, {Top} 0, {Width} 500, {Height} 500);
MainForm.Position := poDesktopCenter; // Will make it Start in the Desktop Center
end;
procedure NotShowForm;
begin
MainForm.ShowModal;
end;
procedure LoadForm;
var
V : TVariantArray;
begin
V := []; // Set Array 0
ThreadSafeCall('NotLoadForm', V); // Use Thread Safe call To make It Load Safely
end;
procedure ShowForm;
var
V : TVariantArray;
begin
V := []; // Set Array 0
ThreadSafeCall('NotShowForm', V); // Use Thread Safe call To make It Load Safely
end;
begin
try
LoadForm;
ShowForm;
finally
FreeForm(MainForm);
except
Writeln('Error: could Not Load Form');
end;
end.Now That We Have Are Form Its Time to Put Are PageControl In!
program AddingTabs;
// Adding PageControl
const
Amount = 10; // How Many Sheets
var
MainForm : TForm; // Are Main TForm
PageControl : TPageControl; // This is Are page Control Wich controls are tabs
TabPages : array [1..Amount] of TTabSheet;
procedure NotLoadForm;
begin
MainForm := CreateForm;
MainForm.SetBounds({left} 0, {Top} 0, {Width} 500, {Height} 500);
MainForm.Position := poDesktopCenter; // Will make it Start in the Desktop Center
PageControl := TPageControl.Create(MainForm);
PageControl.Parent := MainForm;
PageControl.Align := alClient; // Make It Align With The Whole MainForm
end;
procedure NotShowForm;
begin
MainForm.ShowModal;
end;
procedure LoadForm;
var
V : TVariantArray;
begin
V := []; // Set Array 0
ThreadSafeCall('NotLoadForm', V); // Use Thread Safe call To make It Load Safely
end;
procedure ShowForm;
var
V : TVariantArray;
begin
V := []; // Set Array 0
ThreadSafeCall('NotShowForm', V); // Use Thread Safe call To make It Load Safely
end;
begin
try
LoadForm;
ShowForm;
finally
FreeForm(MainForm);
except
Writeln('Error: could Not Load Form');
end;
end.Now That We Have Are PageControl in Lets Add Are Tabs!
program AddingTabs;
// Adding Pages
const
Amount = 10; // How Many Pages ;)
var
MainForm : TForm; // Are Main TForm
PageControl : TPageControl; // This is Are page Control Wich controls are tabs
TabPages : array [1..Amount] of TTabSheet;
procedure NotLoadForm;
var
i : Integer;
begin
MainForm := CreateForm;
MainForm.SetBounds({left} 0, {Top} 0, {Width} 500, {Height} 500);
MainForm.Position := poDesktopCenter; // Will make it Start in the Desktop Center
PageControl := TPageControl.Create(MainForm);
PageControl.Parent := MainForm;
PageControl.Align := alClient; // Make It Align With The Whole MainForm
for i := 1 to Amount do // Amount of Tabs
begin
TabPages[i] := TTabSheet.Create(MainForm);
TabPages[i].Caption := 'Tab ' + Inttostr(i); // The Caption of the title
TabPages[i].PageControl := PageControl; // We Must Identify are Page Control
end;
end;
procedure NotShowForm;
begin
MainForm.ShowModal;
end;
procedure LoadForm;
var
V : TVariantArray;
begin
V := []; // Set Array 0
ThreadSafeCall('NotLoadForm', V); // Use Thread Safe call To make It Load Safely
end;
procedure ShowForm;
var
V : TVariantArray;
begin
V := []; // Set Array 0
ThreadSafeCall('NotShowForm', V); // Use Thread Safe call To make It Load Safely
end;
begin
try
LoadForm;
ShowForm;
finally
FreeForm(MainForm);
except
Writeln('Error: could Not Load Form');
end;
end.EXTRAS (Sender's)
Using OnShow And OnHide
program AddingTabs;
// Performing OnShow And OnHide
const
Amount = 10; // How Many Pages ;)
var
MainForm : TForm; // Are Main TForm
PageControl : TPageControl; // This is Are page Control Wich controls are tabs
TabPages : array [1..Amount] of TTabSheet;
procedure OnShow(Sender : TObject);
begin
TTabSheet(Sender).Caption := 'Current Tab'; // Identify Which Tab Is Currently on
end;
procedure OnHide(Sender : TObject);
begin // Change Tab To Its Olds Caption
TTabSheet(Sender).Caption := 'Tab ' + Inttostr(TTabSheet(Sender).PageIndex+1);
end;
procedure NotLoadForm;
var
i : Integer;
begin
MainForm := CreateForm;
MainForm.SetBounds({left} 0, {Top} 0, {Width} 500, {Height} 500);
MainForm.Position := poDesktopCenter; // Will make it Start in the Desktop Center
PageControl := TPageControl.Create(MainForm);
PageControl.Parent := MainForm;
PageControl.Align := alClient; // Make It Align With The Whole MainForm
for i := 1 to Amount do
begin
TabPages[i] := TTabSheet.Create(MainForm);
TabPages[i].Caption := 'Tab ' + Inttostr(i);
TabPages[i].PageControl := PageControl;
TabPages[i].OnShow := @OnShow;
TabPages[i].OnHide := @OnHide;
end;
end;
procedure NotShowForm;
begin
MainForm.ShowModal;
end;
procedure LoadForm;
var
V : TVariantArray;
begin
V := []; // Set Array 0
ThreadSafeCall('NotLoadForm', V); // Use Thread Safe call To make It Load Safely
end;
procedure ShowForm;
var
V : TVariantArray;
begin
V := []; // Set Array 0
ThreadSafeCall('NotShowForm', V); // Use Thread Safe call To make It Load Safely
end;
begin
try
LoadForm;
ShowForm;
finally
FreeForm(MainForm);
except
Writeln('Error: could Not Load Form');
end;
end.Make Tabs Switchable!!!
in order to switch the tab you must hold Ctrl while dragging it to the other tab.
program AddingTabs;
// Able To Move Tabs Around!!!!
const
Amount = 10;
var
MainForm : TForm; // Are Main TForm
PageControl : TPageControl; // This is Are page Control Wich controls are tabs
TabPages : array [1..Amount] of TTabSheet;
procedure OnMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if (ssCtrl in Shift) then PageControl.BeginDrag(False); // if Ctrl hold down then Start Drag
end;
procedure OnDragDrop(Sender, Source: TObject; X, Y: Integer);
var
i : Integer;
begin
PageControl.ActivePage.PageIndex := PageControl.IndexOfTabAt(X, Y);
end;
procedure OnDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean) ;
begin
Accept := (Sender is TPageControl);
end;
procedure NotLoadForm;
var
i : Integer;
begin
MainForm := CreateForm;
MainForm.SetBounds({left} 0, {Top} 0, {Width} 500, {Height} 500);
MainForm.Position := poDesktopCenter; // Will make it Start in the Desktop Center
PageControl := TPageControl.Create(MainForm);
PageControl.Parent := MainForm;
PageControl.Align := alClient; // Make It Align With The Whole MainForm
PageControl.OnMouseDown := @OnMouseDown;
PageControl.OnDragDrop := @OnDragDrop;
PageControl.OnDragOver := @OnDragOver;
for i := 1 to Amount do
begin
TabPages[i] := TTabSheet.Create(MainForm);
TabPages[i].Caption := 'Tab ' + Inttostr(i);
TabPages[i].PageControl := PageControl;
end;
end;
procedure NotShowForm;
begin
MainForm.ShowModal;
end;
procedure LoadForm;
var
V : TVariantArray;
begin
V := []; // Set Array 0
ThreadSafeCall('NotLoadForm', V); // Use Thread Safe call To make It Load Safely
end;
procedure ShowForm;
var
V : TVariantArray;
begin
V := []; // Set Array 0
ThreadSafeCall('NotShowForm', V); // Use Thread Safe call To make It Load Safely
end;
begin
try
LoadForm;
ShowForm;
finally
FreeForm(MainForm);
except
Writeln('Error: could Not Load Form');
end;
end.