jhildy
2007-09-10 22:15:11
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
[LEFT]Basic form setup
Form editor
[/LEFT]
Done.
Section 2: Buttons
[LEFT]Adding a button
Changing button text
Button events
[/LEFT]
Section 3: Labels
[LEFT]Adding a label
Changing label
[/LEFT]
Section 4: Edit Boxes
[LEFT]Adding an edit box
Getting text from an edit box
Password character
Edit box events[/LEFT]
Section 5: Combo boxes
[LEFT]Adding a combo box
Adding combo box items
Getting combo box text
Combo box events[/LEFT]
Section 6: Check boxes/Radio buttons
[LEFT]Adding check boxes/radio buttons
Check box/radio button checked?
Events[/LEFT]
Section 7: Changing colors
[LEFT]Changing background color
Changing text color
[/LEFT]
Section 8: Misc form objects
[LEFT]Bevels
Group boxes
Images
Progress bar[/LEFT]
Section 9: Multiplayers
[LEFT]Already made a tut on this[/LEFT]
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.
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
The next step is to make the form thread safe and make sure the script shows it. That is where these procedures come in.
The next step is to just call the thread safe procedures in the main loop.
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!
Section 1: Basics
[LEFT]Basic form setup
Form editor
[/LEFT]
Done.
Section 2: Buttons
[LEFT]Adding a button
Changing button text
Button events
[/LEFT]
Section 3: Labels
[LEFT]Adding a label
Changing label
[/LEFT]
Section 4: Edit Boxes
[LEFT]Adding an edit box
Getting text from an edit box
Password character
Edit box events[/LEFT]
Section 5: Combo boxes
[LEFT]Adding a combo box
Adding combo box items
Getting combo box text
Combo box events[/LEFT]
Section 6: Check boxes/Radio buttons
[LEFT]Adding check boxes/radio buttons
Check box/radio button checked?
Events[/LEFT]
Section 7: Changing colors
[LEFT]Changing background color
Changing text color
[/LEFT]
Section 8: Misc form objects
[LEFT]Bevels
Group boxes
Images
Progress bar[/LEFT]
Section 9: Multiplayers
[LEFT]Already made a tut on this[/LEFT]
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.
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.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
frmDesign.Visible := True;TofrmDesign.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.
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.
begin
SafeInitForm;
SafeShowFormModal;
end.After that you will have a script that looks like this.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!