Ok, so you want to learn forms huh? Well i'm gonna make this nice and easy. Just stay with me and you might learn something
Important Notes:
Don't forget to
Rate thread excellent, and rep me .
If you are a leecher, i encourage you to keep reading so that you can make a script for something someone might not have made. .
* means that I will not be going over this on this lesson.
So let's get started!
First lets take you to the form editor.
After you go there look at this picture. I will explain each number and what the item on top of it is.
1: This is a label. You can use it to label an edit box or somewhere along those lines.
2: This is an edit box. This is where you can make people type a short amount of information.
3: This is a memo box. This is where you can display proggys, help etc. You can also make people post a large amount of information.
4: This is a button. You can make people click on it and it will perform an action.
5: This is a checkbox. Multiple amounts of these can be checked. You can make it if a user checks it something will happen.
6: This is a radio box. Only 1 of these may be checked. You can make people choose from a type of things to do. Etc, Use Hotkeys, Use Repeat.
7: This is a list box. Things are listed in here and you can get what the user clicked on.*
8: This is a combobox. You can make mutliple options in this etc, Red, Blue, Green.
9: This is a scroll bar. You can use this to change the amount of minutes before sleeping in a script etc.*
10: This is a groupbox. You can use this to easily group objects together.
11: This is a panel. I have no use for this....*
Now that you know what everything is we can get to actually making the form.
So go ahead and drag a 2 labels, 2 edit buttons, and a button onto the form, so it should look like this,
Then click Label1 and find where it says caption in the object inspector near the left. Type in 'Username:'. Then for Label2 go to caption and type in 'Password:'. Then on the button make the caption 'Login'.
After you've named everything and placed them like this,
save it as 'FormTut1' by clicking the disk thing on the Form Designer.
Now, you are probably wondering 'How the hell do i make this work?'. This is what you do.
First of all close the form window, go to Tools -> Load DFM Form. Then find what you saved yours as and click it. Then you should find a bunch of text in your debug box. Now paste this into your scar window
SCAR Code:
Program New;
Var
Procedure InitForm;
Begin
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.
Then paste the text below where it says
Code:
//Add these objects to variable declarations
var
below the var in the script above. Then find where it says
Code:
///////////////// Generated from: (your form here).dfm
Copy all that text into the InitForm procedure. Now if you run that you see that it only shows for a second then closes. In the debug box you'll find that it says
Code:
[Runtime Error] : Exception: Cannot make a visible window modal in line xx in script C:\Documents and Settings\KyLe\Desktop\Untitled.scar
To fix that just find where it says
SCAR Code:
FrmDesign.Visible := True;
and change it to
SCAR Code:
FrmDesign.Visible := False;
You must remember to ALWAYS change that or else your form will never work .
Now you're wondering 'yea it shows, but it dosent do anything'.
Now it's not going to actually login but it will write in the debug to the text you typed.
So here's how you do that.
Below where it says
put
SCAR Code:
Button1.OnClick := @Test;
The @ symbol means action which sends the name of the sender to the procedure Test.
Now here's what the procedure test is so far
SCAR Code:
Procedure Test(Sender : TObject);
Begin
End;
To make it say what the text you typed do this in it
SCAR Code:
Writeln('In username you typed: ' + Edit1.Text);
Writeln('In password you typed: ' + Edit2.Text);
That will write to the debug box what you typed in the boxes.
Now press run and see what happens.
Now to explain these procedures
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;
You need this procedures to safely call a form. That way if the form has an errror it won't mess up scar. (Well sometimes)
I don't really know actually what they do () but I no that you ALWAYS need them. So whenever you want to make a form show up make these procedures and put this in your main loop
SCAR Code:
SafeInitForm;
SafeShowFormModal;
***This tutorial is not complete yet. I will show you examples of all the types. I have to go to sleep now so I will finish this tomarrow ***