PDA

View Full Version : The form with tabs in your script. How To.



CynicRus
11-13-2012, 04:51 PM
Hey, That is very simple.

In pascal script embended a class: TPageControl. That class is implemented the your tabs container. Tab implemented in TTabSheet class. So, the TPageControl and TTabSheet its all you need for create the you personal form with tabs for you script.

Code example:

var
DsgnForm:TForm;
P: TPageControl;
Tab1,tab2: TTabSheet;
TButton0: TButton;
const
default = 'Comic Sans MS';



procedure YourClickProcedure(Sender: TObject);
begin
ShowMessage('click');
end;


procedure InitForm;
begin
//DsgnForm\\
DsgnForm:=TForm.Create(nil);
with DsgnForm do
begin
Caption:='DsgnForm';
Left:=0;
Top:=0;
Width:=420;
Height:=407;
Font.Name:=default;
Font.Color:=clDefault;
Font.Size:=0;
end;
P:=TPageControl.Create(DsgnForm);
with P do
begin
Parent:=DsgnForm;
Left:=0;
Top:=0;
Width:=420;
Height:=407;
end;
Tab1:=TTabSheet.Create(P);
with Tab1 do
begin
Caption:='Test1';
Left:=0;
Top:=0;
Width:=420;
Height:=407;
Visible:=true;
PageControl:=P;
end;
Tab2:=TTabSheet.Create(P);
with Tab2 do
begin
Caption:='Test2';
Left:=0;
Top:=0;
Width:=420;
Height:=407;
Visible:=true;
PageControl:=P;
end;
P.ActivePage := P.Pages[0];
P.ActivePage := P.Pages[1];

end;

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


procedure ShowFormModal;
begin
DsgnForm.ShowModal;
end;


procedure SafeShowFormModal;
var
v: TVariantArray;
begin
SetArrayLength(V, 0);
ThreadSafeCall('ShowFormModal', v);
end;


begin
SafeInitForm;
SafeShowFormModal;
end.



Code is very simple, just look at that. If you need place any other control or TImage on your tab, you need assign to the control parent you tab index in TpageControl.Pages[youtabindex] property.

Example:

TButton0:=TButton.Create(DsgnForm);
with TButton0 do
begin
Parent:=P.Pages[0];
Caption:='TButton0';
Left:=132;
Top:=154;
Width:=75;
Height:=25;
OnClick:=@YourClickProcedure;
end;


This is all. I hope this can help for anyone.

Cheers, Cynic.

Olly
11-13-2012, 04:53 PM
Thank you :p

Rezozo
11-13-2012, 05:00 PM
Definitely gonna use this!

Press Play
03-01-2013, 05:55 AM
Any help from anyone would be awesome: :)

Is there any way I can change the font options of the tab caption? I tried Caption.Font.Style and Font.Style, but there doesn't seem to be such option :( I just want to make it bold without changing the main font style! I'm sure it's easy, and I'm just over-looking it.