PDA

View Full Version : [TUT] Ultimate Form Guide [TUT]



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===========

Ejjman
01-21-2007, 09:10 PM
Well, it looks really nice, about to read it cuz I need to learn them, but gotta go on PK trip. Good tut, this deserves some rep ++ :)

ronny.m.p
01-29-2007, 11:12 PM
thanks man anyone else find it useful?

Ejjman
01-30-2007, 01:42 AM
Hehe, I found out how to do them long time a go, but anyway, your tut doesn't work so'z ya know.

ronny.m.p
01-31-2007, 11:43 PM
what do you mean dosen't work?

dbrs94
02-01-2007, 02:22 AM
thanks man, nice guide

dbrs94
02-01-2007, 02:24 AM
nice work

yesiammanu
02-01-2007, 05:38 AM
I love the spam that went into the last two posts there, it just makes this such a great experience (for ranting).

Anyways, this doesn't work, sorry.

~~~~Yesiammanu

ronny.m.p
02-04-2007, 02:25 AM
What the hell are you people talking about it dosen't work???

ronny.m.p
02-04-2007, 02:32 AM
EDIT: Added in more detail for people who don't seem to understand it...

rkroxpunk
04-11-2007, 12:05 AM
seeing as no one is telling you why it doesn't work. Well I don't know if this is what everyone else got but I got

[Runtime Error] : Exception: Cannot make a visible window modal in line 51 in script

that was after I made my button and then you told us to add all that crap in line 51 is
ThreadSafeCall('ShowFormModal', v);

in SafeShowFormModal

Oh and don't get me wrong I like this TUT but you don't exactly explain why we do stuff you just say we do it :D

EDIT: When I used your "this is what it should look like" at the end of chapter 5 it worked so i'm guessing you missed something in the TUT. Keep up the good work

ronny.m.p
04-11-2007, 08:57 PM
At the top change the

frmDesign.Visible := true

to:

frmDesign.Visible := false;

;)

rkroxpunk
04-12-2007, 01:14 AM
:confused: I don't see that anywhere?

gsquare567
04-12-2007, 06:09 PM
thanks for the tut, but honestly, i learnt nothing. u need to explain the procedures n stuff, and the properties of form components like a TForm, TButton, etc. also, the buttonclick thing makes no sense, and the procedures you have to include dont make sense.

rkroxpunk
04-13-2007, 06:18 AM
Ya soz I kind of have to agree with him...you just tell us what to do you don't actually explain why we do it

ronny.m.p
04-14-2007, 08:25 PM
Lol guys throw me a bone here. Look at the date that i wrote this. Anyways i'm going to do a complete overhaul of the tut later today. rkroxpunk change visible := true (line 13 of the initform procedure) to visible := false and that should fix your problem. If you are useing my pre-made one then it already has that fixed so it will work.


Ya guys throw him a bone! This tut is 3 months old!

gsquare567
04-15-2007, 04:16 AM
*throws a bone*
wonderin if u know how to use the following events:
OnKeyPress
OnClose
thanks!

ronny.m.p
04-15-2007, 04:44 PM
Yes i do. I will add to my tut later. I'm rewriting right now.

EDIT: Just so you know those arn't the proper names for those events ;)

gsquare567
04-15-2007, 10:19 PM
thats what it says in the list on divi

ronny.m.p
04-17-2007, 07:49 PM
Ohh you mean divi funtions..there called differently in 2.03. But yes i know them for divi..forms are my fav part of divi..i can't wait till srl is updated for it ;)

rkroxpunk
04-19-2007, 11:53 AM
o kwl ronny thx for help

ronny.m.p
04-19-2007, 09:05 PM
Np man.

rkroxpunk
04-22-2007, 02:21 PM
:s thing is all I know how to do now is end a script by hitting a button :D. No idea how you actually do anything with a form. for example fill in a username or something. Could I add your MSN or you add mine (rkroxpunk@hotmail.com) and help me out.
thx
-RK

ronny.m.p
04-22-2007, 07:13 PM
Added.

stein3
05-05-2007, 01:05 PM
it wouldn't stop my script when i pressed the button.

how would i make the script wait until i pressed the button to start? this seems more important.
and how do i use forms to change "const" in the script?

Zika
05-26-2007, 11:38 AM
EDIT: Nvm, i think i typed Type somewhere in the form, and it aint allowed some strange reason.

Its really cool, now im just asking you how the heck i make it connect with a string like:

WhatToSay = 'Test';

And make it in the form to chance whats in the script :S

Ashur2Good
05-26-2007, 12:01 PM
nice tut, i think i kinda get how to make forms properly now ;)

8/10


-Ashur

ronny.m.p
05-26-2007, 01:55 PM
Well as promised i just updated the tut to fix some problems people have had. It explains in more detail now too ;)

n3ss3s
05-28-2007, 10:44 AM
good tut.

Dead Link
06-08-2007, 11:00 AM
Hey
Great tutorial
Quite useful

I have a problem though

I made this script and getting one small problem

In my main loop, it first goes for SetupScript, then SetupSRL and then a repeat until loop that pulls of my main procedures

I used the form only to take data from the user
The data taken is used when the user presses F2

Now the problem is that after it shows the form, pressing F2 does nothing
but if i close the form ( by pressing x ), the main part starts working

As in now after closing the form, if i press f2 it does what it was made to do

Which means that until i close the form, its not moving on in the script
anyway to help me ?

Edit:I forgot to mention

It was working perfectly earlier
Then i changed the bordertype to dialog and it stopped working
So I thought i must have messed up something while changing it.
I re-did the form coz of this but its still not working

gsquare567
06-08-2007, 03:25 PM
anybody know how to select/deselect items in a TListBox? i've tried ListBox.Items.Select('Item1Text') := True; and ListBox.Items.Select(0) := True; but it says Select is an unknown identifier.

Lalaji
06-08-2007, 04:22 PM
Great TUT!

Very useful

x13om13e12x
06-27-2007, 11:49 PM
how do you add multiplayer to forms, i havent seen any TUTs for it and i could only thing of making 10 text boxes on the same spot, and then depending on which one someone is inputing info on it hides one and shows another, and then have an array declaring users of 0 to how many times someone pressed add user minus 1 or soemthing. But im not sure if that would work

alfonso1024
08-03-2007, 10:41 PM
i need help by iam trying to do a scrip or form more as a form that has



[ save ]=button
[ ] = space to fill the user imfo


Main page

[setup player]

[settings]


[start]

easy? right?
but i want when i press setup player it send me to another form and be like this

[<==] [create] [cancel] [==>]


username [ ]
password [ ]

what smithing?[ ]

[save]

and when i press save i go to the main page.

then another form that when i press [settings] it takes me to this


settings

how many loads?[ ]



[save]



is that easy??..... can u take it? and can u show me =)



i need the codes like

to press a boton and cancel like this toturial


Button1.OnClick:= @buttonclick;

thats a basic one i want for all things i put up there thank you all of ya!

[ save ]=button
[ ] = space to fill the user imfo

sink998
08-25-2008, 01:38 AM
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===========

Umm could you explain how to make it so they type the username and pass to login and a thing where they choose how many times it repeats would help.