ronny.m.p
01-19-2007, 11:38 PM
Ok, let me start off by saying that I have seen alot of questions about forms lately so I decided to post a thread that explains them as best I can.
Table Of Contents:[
Chapter 1: Introduction to forms
Chapter 2: The need for forms
Chapter 3: Variables used with forms
Chapter 4: Procedures used with forms
Chapter 5: Form creation
Chapter 6: Creating a basic form
Chapter 7: Adding pictures
Chapter 8: End Notes
Chapter 9: Credits
==================Start of guide=================
===Chapter 1: Introduction to forms===
When your useing a computer you are around forms 24/7. Just about every program uses forms in one context or another. So you ask yourself, "Ok, but what are forms?" Well forms are, in simplest terms, a menu. Think about a DVD menu or if your filling out an online question sheet. These examples require you to give it information before you can start what you want to do. This is much like the forms that you will be useing in SCAR.
===End of Chapter 1===
===Chapter 2: The need for forms===
Forms are mainly used at the start of the script to get information from the user. They are much more user-friendly and professional then a long setup area in the script, although you still may need a setup. Forms can be used for anything from getting a username to stateing which tree to cut to compileing authentication codes.
===End of Chapter 2===
===Chapter 3: Variables used with forms
Forms use very different vars then you are probably used to. You can always tell a form var by haveing the letter T at the beginning. If you were to try and use these vars for something differnt your script would mess up and leave you hanging. There are many differnt types of form vars but i have made a list of some of the more common ones below.
frmDesign : TForm; This one is in every form and is the design of the form
Label1 : TLabel; This is text
Button1 : TButton; This is a button to press
===End of Chapter 3===
===Chapter 4: Procedures used with forms===
Much like the chapter above, forms use some procedures that probably wouldn't be much use anywhere else. For example forms need 4 key procedures. These procedures are:
InitForm
SafeInitForm
ShowFormModel
SafeShowFormModel
As you can see each procedure needs another procedure to porperly load it AKA a "safe" procedure.
===End of Chapter 4===
===Chapter 5: Form Creation===
Ok, now you should have a good idea what forms are and what there used for. Now let's take a look at the form that we will be useing to make this form, kind of funny but it is a form. There wasn't much use writing this so i made an image that should greatly simplify it. Start by going to Tools/Form Editor. Notes: If it is to small then copy+paste to MS paint and zoom in.
http://img404.imageshack.us/img404/9170/untitled2dx6.jpg (http://imageshack.us)
===End of Chapter 5===
===Chapter 6: Createing a basic form===
Ok, now you know about the form creator now let's start useing it. Open up the form editor. Now you will see a button on the Form Designer window, it should have OK writen in it. Click the symbol and press anywhere on the menu. Now press the save. Exit the Form Editor and go back to scar. Now go Tools/Load DFM form. Open your form and you should see a bunch of text in the debug box. Firstly copy the vars into your vars section. Next make a procedure called InitForm. Copy the rest of the text under that procedure. The next is a bit complicated but is the same for just about everything so i will post it here as 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;
procedure SetupScript;
begin
SafeInitForm;
SafeShowFormModal;
end;
What this does is it compiles the form and prepairs to launch it. This is a VERY important step in form creation.
Now we must make the form visible. Find where it says:
frmDesign.Visible := True;
And change it to :
frmDesign.Visible := False;
Now put SetupScript as the first part of your main loop. Press run and a window should popup with your menu. Right now by pressing the button nothing will happen so let's fix that. First find this, or something like this, in your InitForm procedure:
Button1 := TButton.Create(frmDesign);
Button1.Parent := frmDesign;
Button1.Left := 163;
Button1.Top := 285;
Button1.Width := 75;
Button1.Height := 25;
Button1.Caption := 'Start';
Button1.TabOrder := 8;
Now we have to tell it to do something. SO first off create a new procedure above InitForm and call it:
procedure buttonclick(sender: TObject);
begin
frmDesign.Caption:= frmDesign.Caption + '.';
frmDesign.ModalResult:= mrOk;
end;
This tells the form to close when the button is pushed. AKA mrOk;.
Next go back to that spot in IntiForm and add in:
Button1.OnClick:= @buttonclick;(this tells it where to look) So it should now look like this:
Button1 := TButton.Create(frmDesign);
Button1.Parent := frmDesign;
Button1.OnClick:= @buttonclick;
Button1.Left := 163;
Button1.Top := 285;
Button1.Width := 75;
Button1.Height := 25;
Button1.Caption := 'Start';
Button1.TabOrder := 8;
Now press run again. When you press your button the script should end. Congratz you just made a form.
Here is what it should look like:
program New;
var
frmDesign : TForm;
Button1 : TButton;
procedure buttonclick(sender: TObject);
begin
frmDesign.Caption:= frmDesign.Caption + '.';
frmDesign.ModalResult:= mrOk;
end;
procedure InitForm;
begin
frmDesign := CreateForm;
frmDesign.Left := 250;
frmDesign.Top := 114;
frmDesign.Width := 696;
frmDesign.Height := 480;
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;
Button1 := TButton.Create(frmDesign);
Button1.Parent := frmDesign;
Button1.OnClick:= @buttonclick;
Button1.Left := 163;
Button1.Top := 285;
Button1.Width := 75;
Button1.Height := 25;
Button1.Caption := 'Start';
Button1.TabOrder := 8;
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;
procedure SetupScript;
begin
SafeInitForm;
SafeShowFormModal;
end;
begin
SetupScript;
end.
===End of Chapter 6===
===Chapter 7: Adding pictures===
I'm going to make this chapter short because it is quite complex and not a real nessesity. The coords for it are quite differnt but if you wish to know more about this i sugest StarBlaster's Tut.
Procedure AddPic; // Loading a Picture
var
Picture : integer;
Canvas : TCanvas;
begin
Picture := LoadBitmap() // Bitmap here
Canvas:= GetBitmapCanvas(Picture); VVV Coords VVV
CopyCanvas(Canvas, frmDesign.Canvas, 1, -1, 300, 520, 0, 0, 315, 520);
end;
Procedure FormPaintStar(Sender : TObject); // Adding a picture
begin
AddPic;
end;
===End of Chapter 7===
===Chapter 8: End notes===
Forms are very powerful and fun. You can customize them by adding things like memos and text and differernt selection tools. But remember to not go too overboard...like 6 million pictures on a 40X40 canvas. But don't forget to have fun. And remember they really help the user to get the most out of your script.
===End of Chapter 8===
===Chapter 9: Credits===
Thankyou to everyone who helped me to get started scripting that long time ago...
This Tut is being released on Sythe and Villu-reborn. If you wish to post it elsewhere ask my premission first.
If you like it then please post your comments.
===End of chapter 9===
============End of Guide===========
Table Of Contents:[
Chapter 1: Introduction to forms
Chapter 2: The need for forms
Chapter 3: Variables used with forms
Chapter 4: Procedures used with forms
Chapter 5: Form creation
Chapter 6: Creating a basic form
Chapter 7: Adding pictures
Chapter 8: End Notes
Chapter 9: Credits
==================Start of guide=================
===Chapter 1: Introduction to forms===
When your useing a computer you are around forms 24/7. Just about every program uses forms in one context or another. So you ask yourself, "Ok, but what are forms?" Well forms are, in simplest terms, a menu. Think about a DVD menu or if your filling out an online question sheet. These examples require you to give it information before you can start what you want to do. This is much like the forms that you will be useing in SCAR.
===End of Chapter 1===
===Chapter 2: The need for forms===
Forms are mainly used at the start of the script to get information from the user. They are much more user-friendly and professional then a long setup area in the script, although you still may need a setup. Forms can be used for anything from getting a username to stateing which tree to cut to compileing authentication codes.
===End of Chapter 2===
===Chapter 3: Variables used with forms
Forms use very different vars then you are probably used to. You can always tell a form var by haveing the letter T at the beginning. If you were to try and use these vars for something differnt your script would mess up and leave you hanging. There are many differnt types of form vars but i have made a list of some of the more common ones below.
frmDesign : TForm; This one is in every form and is the design of the form
Label1 : TLabel; This is text
Button1 : TButton; This is a button to press
===End of Chapter 3===
===Chapter 4: Procedures used with forms===
Much like the chapter above, forms use some procedures that probably wouldn't be much use anywhere else. For example forms need 4 key procedures. These procedures are:
InitForm
SafeInitForm
ShowFormModel
SafeShowFormModel
As you can see each procedure needs another procedure to porperly load it AKA a "safe" procedure.
===End of Chapter 4===
===Chapter 5: Form Creation===
Ok, now you should have a good idea what forms are and what there used for. Now let's take a look at the form that we will be useing to make this form, kind of funny but it is a form. There wasn't much use writing this so i made an image that should greatly simplify it. Start by going to Tools/Form Editor. Notes: If it is to small then copy+paste to MS paint and zoom in.
http://img404.imageshack.us/img404/9170/untitled2dx6.jpg (http://imageshack.us)
===End of Chapter 5===
===Chapter 6: Createing a basic form===
Ok, now you know about the form creator now let's start useing it. Open up the form editor. Now you will see a button on the Form Designer window, it should have OK writen in it. Click the symbol and press anywhere on the menu. Now press the save. Exit the Form Editor and go back to scar. Now go Tools/Load DFM form. Open your form and you should see a bunch of text in the debug box. Firstly copy the vars into your vars section. Next make a procedure called InitForm. Copy the rest of the text under that procedure. The next is a bit complicated but is the same for just about everything so i will post it here as 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;
procedure SetupScript;
begin
SafeInitForm;
SafeShowFormModal;
end;
What this does is it compiles the form and prepairs to launch it. This is a VERY important step in form creation.
Now we must make the form visible. Find where it says:
frmDesign.Visible := True;
And change it to :
frmDesign.Visible := False;
Now put SetupScript as the first part of your main loop. Press run and a window should popup with your menu. Right now by pressing the button nothing will happen so let's fix that. First find this, or something like this, in your InitForm procedure:
Button1 := TButton.Create(frmDesign);
Button1.Parent := frmDesign;
Button1.Left := 163;
Button1.Top := 285;
Button1.Width := 75;
Button1.Height := 25;
Button1.Caption := 'Start';
Button1.TabOrder := 8;
Now we have to tell it to do something. SO first off create a new procedure above InitForm and call it:
procedure buttonclick(sender: TObject);
begin
frmDesign.Caption:= frmDesign.Caption + '.';
frmDesign.ModalResult:= mrOk;
end;
This tells the form to close when the button is pushed. AKA mrOk;.
Next go back to that spot in IntiForm and add in:
Button1.OnClick:= @buttonclick;(this tells it where to look) So it should now look like this:
Button1 := TButton.Create(frmDesign);
Button1.Parent := frmDesign;
Button1.OnClick:= @buttonclick;
Button1.Left := 163;
Button1.Top := 285;
Button1.Width := 75;
Button1.Height := 25;
Button1.Caption := 'Start';
Button1.TabOrder := 8;
Now press run again. When you press your button the script should end. Congratz you just made a form.
Here is what it should look like:
program New;
var
frmDesign : TForm;
Button1 : TButton;
procedure buttonclick(sender: TObject);
begin
frmDesign.Caption:= frmDesign.Caption + '.';
frmDesign.ModalResult:= mrOk;
end;
procedure InitForm;
begin
frmDesign := CreateForm;
frmDesign.Left := 250;
frmDesign.Top := 114;
frmDesign.Width := 696;
frmDesign.Height := 480;
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;
Button1 := TButton.Create(frmDesign);
Button1.Parent := frmDesign;
Button1.OnClick:= @buttonclick;
Button1.Left := 163;
Button1.Top := 285;
Button1.Width := 75;
Button1.Height := 25;
Button1.Caption := 'Start';
Button1.TabOrder := 8;
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;
procedure SetupScript;
begin
SafeInitForm;
SafeShowFormModal;
end;
begin
SetupScript;
end.
===End of Chapter 6===
===Chapter 7: Adding pictures===
I'm going to make this chapter short because it is quite complex and not a real nessesity. The coords for it are quite differnt but if you wish to know more about this i sugest StarBlaster's Tut.
Procedure AddPic; // Loading a Picture
var
Picture : integer;
Canvas : TCanvas;
begin
Picture := LoadBitmap() // Bitmap here
Canvas:= GetBitmapCanvas(Picture); VVV Coords VVV
CopyCanvas(Canvas, frmDesign.Canvas, 1, -1, 300, 520, 0, 0, 315, 520);
end;
Procedure FormPaintStar(Sender : TObject); // Adding a picture
begin
AddPic;
end;
===End of Chapter 7===
===Chapter 8: End notes===
Forms are very powerful and fun. You can customize them by adding things like memos and text and differernt selection tools. But remember to not go too overboard...like 6 million pictures on a 40X40 canvas. But don't forget to have fun. And remember they really help the user to get the most out of your script.
===End of Chapter 8===
===Chapter 9: Credits===
Thankyou to everyone who helped me to get started scripting that long time ago...
This Tut is being released on Sythe and Villu-reborn. If you wish to post it elsewhere ask my premission first.
If you like it then please post your comments.
===End of chapter 9===
============End of Guide===========