Hey this is my complete form tutorial. I am going to compile all my knowledge about forms together to make one massive tutorial. I will break it down into sections. Since i have school i will not release this all at once but when i get the time.
Section 1: Basics
Basic form setup
Form editor
Done.
Section 2: Buttons
Adding a button
Changing button text
Button events
Section 3: Labels
Adding a label
Changing label
Section 4: Edit Boxes
Adding an edit box
Getting text from an edit box
Password character
Edit box events
Section 5: Combo boxes
Adding a combo box
Adding combo box items
Getting combo box text
Combo box events
Section 6: Check boxes/Radio buttons
Adding check boxes/radio buttons
Check box/radio button checked?
Events
Section 7: Changing colors
Changing background color
Changing text color
Section 8: Misc form objects
Bevels
Group boxes
Images
Progress bar
Section 9: Multiplayers
Already made a tut on this
Basics
Basic form setup
The basic way to set up a form is described in the scar manual. I will post here and explain this further though.
SCAR Code:
program New;
var
frmDesign : TForm;
procedure InitForm;
begin
frmDesign := CreateForm;
frmDesign.Left := 259;
frmDesign.Top := 132;
frmDesign.Width := 354;
frmDesign.Height := 254;
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;
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.
This is the base of every form created through the form editor. The first thing done is the forms variables are created.
SCAR Code:
program New;
var
frmDesign : TForm;
procedure InitForm;
begin
frmDesign := CreateForm;
frmDesign.Left := 259;
frmDesign.Top := 132;
frmDesign.Width := 354;
frmDesign.Height := 254;
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 := True;
frmDesign.PixelsPerInch := 96;
end;
If you used a form editor to get the form it will basically give you this code.
This is just the variable frmDesign declared as a Tform. Then it is created through the procedure initform. What you made the form look like in the form editor will all be labeled here.
One thing you must remember though is to change
SCAR Code:
frmDesign.Visible := True;
To
SCAR Code:
frmDesign.Visible := False;
If you do not you will get an error.
The next step is to make the form thread safe and make sure the script shows it. That is where these procedures come in.
SCAR Code:
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;
The reason is has to be thread safe is because there is a good chance scar will crash. Most of scars functions already are thread safe but not all of them are.
The next step is to just call the thread safe procedures in the main loop.
SCAR Code:
begin
SafeInitForm;
SafeShowFormModal;
end.
After that you will have a script that looks like this.
SCAR Code:
program New;
var
frmDesign : TForm;
procedure InitForm;
begin
frmDesign := CreateForm;
frmDesign.Left := 259;
frmDesign.Top := 132;
frmDesign.Width := 354;
frmDesign.Height := 254;
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;
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.
They press play and you will see a blank form.
Form editor
The form editor is an easy to use built in feature of scar. It makes form making extremely easy when it comes to designing the form. I will explain the basic components of the form editor in this section.
You can open the form editor by going to Tools->Form editor
This is what you see when you click on the form editor.
The form template is where you drag your items to. The objects are what you are putting on the form. The object inspector is how you change the properties of objects. I will go into more detail with each tutorial that comes up.
More to come when i get the time!