View Full Version : THE big form tutorial ~ by MK
MasterKill
02-01-2009, 07:26 PM
THE big form tutorial ~ by MasterKill
Some people might have noticed that I like to make nice forms for the setup of my scripts. I’m going to teach you guys how it’s done, and how you can make a nice form yourself.
This is what you should be able to make at the end of the tutorial:
http://img5.imageshack.us/img5/6927/formimage10gifrt7.gif
Components
TForm; (http://www.villavu.com/forum/showpost.php?p=520195)
TButton; (http://www.villavu.com/forum/showpost.php?p=520197)
TLabel; (http://www.villavu.com/forum/showpost.php?p=520198)
TEdit; (http://www.villavu.com/forum/showpost.php?p=520204)
TComboBox; (http://www.villavu.com/forum/showpost.php?p=520206)
TListBox; (http://www.villavu.com/forum/showpost.php?p=520207)
TImage; (http://www.villavu.com/forum/showpost.php?p=520209)
TTimer; (http://www.villavu.com/forum/showpost.php?p=520210)
Player form
Create a player setup form (http://www.villavu.com/forum/showpost.php?p=520212) (multi player obviously!)
Save & Load players into the form (http://www.villavu.com/forum/showpost.php?p=520213) (not done)
Advanced components
Other components (http://www.villavu.com/forum/showpost.php?p=520214) (not done)
I hope you'll learn a lot from it and that it gives you an nice result!
Good luck!
Wall of fame:
http://i25.tinypic.com/5x7voh.jpg
Been working on that for quite a while, still a flaw with the RadioButton, should sort it soon.
All learned from this tutorial:
http://img300.imageshack.us/img300/8352/formfinished.png
Thanks mucho... never really learned this stuff until now. Easier than I thought it would be. xD Maybe finish the player array stuff... I might try my hand at it on a 3 hour drive home I got tomorrow though.
http://img24.imageshack.us/img24/69/sfycimageshcaks.jpg
MasterKill: Adding and delting players, ect :D Tabs (Thx to you)
Thanks so much. I made this about a week ago on like 3 car trips. tysm :)
http://i43.tinypic.com/wjgllf.jpg
:)
I learned it from this tut, well the TImage part :)
MasterKill
02-01-2009, 07:27 PM
TForm;
The first step of making your form, is the TForm; We will call our form frmDesign, wish is most used. Before you can start working on your form, you need some standard functions for creating your form, and making it visible. The “standard stuff”:
var
frmDesign: TForm;
procedure InitForm;
begin
// This is where you'll build your form
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; // those 2 function are the action form setup. Thise one creates your form
SafeShowFormModal; // and this one makes it visible
end.
Now, you don’t have a working form yet. To get our “FORM” we are going to create our background. The big base of the form.
procedure InitForm;
begin
frmDesign := CreateForm; // This will create your form. MUST be called first.
frmDesign.Left := 100; // How many pixels from the left must the form be vissible?
frmDesign.Top := 100; // How many pixels from the top must the form be vissible?
frmDesign.Width := 500; // The width of you form in pixels
frmDesign.Height := 500; // The height of you form in pixels
frmDesign.Caption := 'Test!'; // The name of your form? This will be shown in the upper left balk
frmDesign.Color := ClWhite; // The background color of your form ("ClWhite", "ClBlack" ect, or just an color like: 123456)
end;
Take a good look at those, this will be the base of your form. Play around a lil with those vars and see what they do. Don’t forget to add the “standard stuff” that I showed earlier!
If you want to go more advanced, you can do more stuff with the TForm. Decide the “standard” color for you text(TLabel) in the form, or what font it should be.
frmDesign.Font.Color := ClBlack; // The color of the text (Tlabels) when you have those
frmDesign.Font.Name := 'Comic Sans MS'; // The name of the font you want the Tlabels to be
Congratulations! You now know how to make the very basics of a form!
Advanced TForm;
If you don’t like the “close” and “minisize” button in the upper right corner you could add the following code to your form, wish is OPTIONAL, if you want to hide those.
frmDesign.BorderStyle := bsNone;
NOTE: If you use this, you should make a CLOSE button! I’ll learn you later in the tutorial how to make one. But for now, if you want to test it, Press “ALT + F4” to close the form and stop the script.
FAQ TForm;
no questions yet.
What do we have now?
var
frmDesign: TForm;
procedure InitForm;
begin
frmDesign := CreateForm; // This will create your form. MUST be called first.
frmDesign.Left := 100; // How many pixels from the left must the form be vissible?
frmDesign.Top := 100; // How many pixels from the top must the form be vissible?
frmDesign.Width := 500; // The width of you form in pixels
frmDesign.Height := 500; // The height of you form in pixels
frmDesign.Caption := 'Test!'; // The name of your form? This will be shown in the upper left balk
frmDesign.Color := ClWhite; // The background color of your form ("ClWhite", "ClBlack" ect, or just an color like: 123456)
frmDesign.Font.Color := ClBlack; // The color of the text (Tlabels) when you have those
frmDesign.Font.Name := 'Comic Sans MS'; // The name of the font you want the Tlabels to be
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; // those 2 function are the action form setup. Thise one creates your form
SafeShowFormModal; // and this one makes it visible
end.
End of TForm;
MasterKill
02-01-2009, 07:28 PM
TButton;
Before you start you should know how the TForm; works ans how to make use of it.
Adding an button to your form. Might not sound that hard, but behind a button is a procedure. Cause, if you click on the button you want something to happen. First we are going to add our button to the global vars.
var
frmDesign: TForm;
Button1: TButton; // there we go
Now, we have to “create” our button in the form, wich will go like the following:
Button1 := TButton.Create(FrmDesign); // This will create the button. Must be called.
Button1.Parent := FrmDesign; // The parent is very important. Without the parrent set to the formname the button won't be visible
Button1.Left := 10; // how many pixels from the left
Button1.Top := 425; // how many pixels from the top
Button1.Height := 30; // the height of the button
Button1.Width := 100; // the width of the button
Button1.Caption := 'Close form'; // The text on the button!
Run your script, and you see your shiny button. But, when you click on it, nothing is happening! That’s right, nothing happends. To let the form know what to do you have to add an “OnClick” option. Note: the procedure for the button is a bit different then other procedures, and it will only work if you call it this way:
Add this to your form setup:
Button1.OnClick := @ButtonClick; //Dont forget the @
And make this new procedure above your form setup:
Procedure ButtonClick(Sender: TObject);
Begin
// what to do if the button is clicked!
End;
Of course you can rename the procedure to whatever you like. But what is the (Sender: TObject);. That is for the script to know that the procedure is called by a TObject. A TObject can be anything form your form. A TButton, TLabel, TEdit, ect. The TObject where you clicked on will be returned as the Sender. And In this case the sender will be Button1.
Now, when you click the button, still nothing is happening. But it sure is calling your procedure I’ll tell you! Just add some WriteLn(‘’) to your procedure to see if it’s working.
Now, we called our button ‘Close form’. To make that actually happening, you will have to add the following code to your ButtonClick procedure:
Procedure ButtonClick(Sender: TObject);
Begin
WriteLn(‘closing form!’);
frmDesign.ModalResult:= mrOk;
End;
When you have called that line, your form will close and your script will resume.
Congratulations! You now know how to add buttons to your form!
Advanced TButton;
When you make more then 1 button, I suggest you put those in an array! This will shorten your code up a lot and it looks more advanced, but easier to overview though!
Small example:
Var
Buttons: Array [0..1] Of TButton; // the var you need to add
Index: Integer; // we need this for you loop;
// the onclick procedure:
Procedure ButtonClick(Sender: TObject);
Begin
Case Sender Of
Buttons[0]: Begin
WriteLn(‘start!’);
End;
Buttons[1]: Begin
WriteLn(‘stop!’);
End;
End;
End;
// the following in your form setup:
For Index := 0 To 1 Do
Begin
Buttons[Index] := TButton.Create(FrmDesign);
Buttons[Index].Parent := FrmDesign;
Buttons[Index].Height := 20;
Buttons[Index].Width := 100;
Buttons[Index].Left := 10;
Buttons[Index].Top := 10 + (Index * 30); //this will but the buttons in a nice line
Buttons[Index].OnClick := @ButtonClick;
End;
Buttons[0].Caption := ‘Start’;
Buttons[1].Caption := ‘Stop’; // you can also make a string array of those and put this in your loop to.
FAQ TButton;
no questions yet.
What do we have now?
var
frmDesign: TForm;
Button1: TButton;
Procedure ButtonClick(Sender: TObject);
Begin
WriteLn('closing form!');
frmDesign.ModalResult:= mrOk;
End;
procedure InitForm;
begin
{ The TForm; part }
frmDesign := CreateForm; // This will create your form. MUST be called first.
frmDesign.Left := 100; // How many pixels from the left must the form be vissible?
frmDesign.Top := 100; // How many pixels from the top must the form be vissible?
frmDesign.Width := 500; // The width of you form in pixels
frmDesign.Height := 500; // The height of you form in pixels
frmDesign.Caption := 'Test!'; // The name of your form? This will be shown in the upper left balk
frmDesign.Color := ClWhite; // The background color of your form ("ClWhite", "ClBlack" ect, or just an color like: 123456)
frmDesign.Font.Color := ClBlack; // The color of the text (Tlabels) when you have those
frmDesign.Font.Name := 'Comic Sans MS'; // The name of the font you want the Tlabels to be
{ The TButton; part }
Button1 := TButton.Create(FrmDesign); // This will create the button. Must be called.
Button1.Parent := FrmDesign; // The parent is very important. Without the parrent set to the formname the button won't be visible
Button1.Left := 10; // how many pixels from the left
Button1.Top := 425; // how many pixels from the top
Button1.Height := 30; // the height of the button
Button1.Width := 100; // the width of the button
Button1.Caption := 'Close form'; // The text on the button!
Button1.OnClick := @ButtonClick;
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; // those 2 function are the action form setup. Thise one creates your form
SafeShowFormModal; // and this one makes it visible
end.
End of TButton;
MasterKill
02-01-2009, 07:29 PM
TLabel;
Fist of all, what are TLabels exactly. A TLabel is a line of text sort of implanted to the background. Other people can't change the text while the form is open but you can with some code.
So lets add our TLabel to the vars (We will use the script from the TButton tutorial!)
var
frmDesign: TForm;
Button1: TButton;
Label1: TLabel;
Now, to add the label to your form, you have to add this to your form setup:
Label1 := TLabel.Create(FrmDesign); // This will create the label. Must Be called.
Label1.Parent := FrmDesign; // The parent is very important. Without the parrent set to the formname the label wont be visible
Label1.Top := 10; // how many pixels from the left
Label1.Left := 10; // how many pixels from the top
Label1.Caption := 'A form tut label!'; // What does your label need to say?
Your text seems to be a bit small, and you don't like the font to much. To edit the font you add this to your script:
Label1.Font.Size := 18; // The size of your text
Label1.Font.Color := ClRed; // The color of your text
Label1.Font.Name := 'Comic Sans MS'; // The font name of your text
Fun a bit around with those variables to know what there exactly doing.
You can use labels for your credits, but you can also change the labels name when some one presses a button for example.
If you take a good look at this code and run the script, you can exactly see how it's done:
var
frmDesign: TForm;
Button1: TButton;
Label1: TLabel;
Count: Integer; // This variable will be used for the counting!
Procedure ButtonClick(Sender: TObject);
Begin
Count := Count + 1;
Label1.Caption := 'You currently have: ' + IntToStr(Count); // this is where it updates the labels text when the button is pressed.
End;
procedure InitForm;
begin
{ The TForm; part }
frmDesign := CreateForm;
frmDesign.Left := 100;
frmDesign.Top := 100;
frmDesign.Width := 500;
frmDesign.Height := 500;
frmDesign.Caption := 'Test!';
frmDesign.Color := ClWhite;
frmDesign.Font.Color := ClBlack;
frmDesign.Font.Name := 'Comic Sans MS';
{ The TButton; part }
Button1 := TButton.Create(FrmDesign);
Button1.Parent := FrmDesign;
Button1.Left := 10;
Button1.Top := 425;
Button1.Height := 30;
Button1.Width := 100;
Button1.Caption := '+ 1!';
Button1.OnClick := @ButtonClick;
{ The TLabel; Part }
Label1 := TLabel.Create(FrmDesign); // This will create the label. Must Be called.
Label1.Parent := FrmDesign; // The parent is very important. Without the parrent set to the formname the label wont be visible
Label1.Top := 10; // how many pixels from the left
Label1.Left := 10; // how many pixels from the top
Label1.Caption := 'You currently have: 0';// What does your label need to say?
Label1.Font.Size := 18; // The size of your text
Label1.Font.Color := ClRed; // The color of your text
Label1.Font.Name := 'Comic Sans MS'; // The font name of your text
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.
Congratulations! You now know how to add labels to your form!
Advanced TLabel;
When you have more then one label, it's nice to put your labels in an array. This will make you code shorter and easy to overview your form.
Here is some small code to see how it's done:
Var
Labels: Array [0..5] Of TLabel;
LabelName: Array Of String;
Index: Integer; // needed for the loop
// this should be in your form setup:
LabelName := ['first label text', 'second label text', 'third label text', 'fourth label text', 'fifth label text', 'last label text'];
For Index := 0 To 5 Do
Begin
Labels[Index] := TLabel.Create(FrmDesign);
Labels[Index].Parent := FrmDesign;
Labels[Index].Left := 10;
Labels[Index].Top := 10 + (30 * Index); // this will nicely line it up
Labels[Index].Caption := LabelName[Index];
End;
FAQ TLabel;
no questions yet.
End of TLabel;
MasterKill
02-01-2009, 07:30 PM
TEdit;
A TEdit, is a place where users can put something in. Your name for example. In this part I'll teach how to make and use a TEdit; Before you start on the TEdit, you should know how to use the TForm, TLabel and TButton already.
Lets add our TEdit to the global variables.
Var
Edit1: TEdit;
Once you have that, you have to actual create the Editbox in the box. You do that by adding the following code to your form setup:
Edit1 := TEdit.Create(FrmDesign); // This will create the editbox. Must be called.
Edit1.Parent := FrmDesign; // without this your editbox wont be visible
Edit1.Top := 30; // how many pixels from the top
Edit1.Left := 10; // how many pixels from the left
Edit1.Width := 350; // the width of your editbox
Edit1.Height := 20; // the height of you editbox
There, you now have a shiny TEdit. Now, to actual let it do something.
If you want to have some text in the box, you can add this:
Edit1.Text := 'enter your name here';
Now, when you open your form again you'll see your text in the box. This can be edited by the user to whatever he wants. Reading what's in the box goes the same.
Now, lets make a form where an TEdit is needed.
var
frmDesign: TForm;
Button1: TButton;
Label1: TLabel;
Edit1: TEdit;
Procedure ButtonClick(Sender: TObject);
Begin
frmDesign.ModalResult:= mrOk;
ShowMessage('Hello ' + Edit1.Text + '!'); // here you see that it will call your name, wich you putted in the TEdit;
End;
procedure InitForm;
begin
{ The TForm; part }
frmDesign := CreateForm;
frmDesign.Left := 100;
frmDesign.Top := 100;
frmDesign.Width := 500;
frmDesign.Height := 100;
frmDesign.Caption := 'Test!';
frmDesign.Color := ClWhite;
frmDesign.Font.Color := ClBlack;
frmDesign.Font.Name := 'Comic Sans MS';
{ The TButton; part }
Button1 := TButton.Create(FrmDesign);
Button1.Parent := FrmDesign;
Button1.Left := 375;
Button1.Top := 30;
Button1.Height := 20;
Button1.Width := 100;
Button1.Caption := 'OK';
Button1.OnClick := @ButtonClick;
{ The TLabel; Part }
Label1 := TLabel.Create(FrmDesign);
Label1.Parent := FrmDesign;
Label1.Top := 10;
Label1.Left := 10;
Label1.Caption := 'what is your name?';
{ The TEdit; Part }
Edit1 := TEdit.Create(FrmDesign); // This will create the editbox. Must be called.
Edit1.Parent := FrmDesign; // without this your editbox wont be visible
Edit1.Top := 30; // how many pixels from the top
Edit1.Left := 10; // how many pixels from the left
Edit1.Width := 350; // the width of your editbox
Edit1.Height := 20; // the height of you editbox
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.
Congratulations! You now know how to add editboxes to your form!
Advanced TEdit;
You can limit users in what to put in the TEdit. Scar has the following properties:
.MaxLength := 4;
The user will not be able to put more then 4 chars in your editbox now. Usefull for Players[].Pin for example.
.PasswordChar := '*';
This is very useful to hide passwords! if you type: P@SSW0RD, you will only see "********", but when you get the text of your box (string := Edit.Text) you'll get P@SSW0RD again :)
FAQ TEdit;
no questions yet.
End of TEdit;
MasterKill
02-01-2009, 07:31 PM
TComboBox;
A TComboBox is almost the same as a TEdit;. Except, you can add "choose able" options to your combo box. A sort of option list. In this tutorial part I'll show you how to made a TComboBox and add Items to your "option list".
http://img89.imageshack.us/img89/5517/tcomboboxwt4.png
First of all, lets add the TComboBox to your global vars.
Var
ComboBox1: TComboBox;
Once you have that, you have to actual create the combobox in the form. You do that by adding the following code to your form setup:
ComboBox1 := TComboBox.Create(FrmDesign); // This will create the combobox. Must be called.
ComboBox1.Parent := FrmDesign; // without this your combobox wont be visible
ComboBox1.Top := 30; // how many pixels from the top
ComboBox1.Left := 10; // how many pixels from the left
ComboBox1.Width := 350; // the width of your combobox
ComboBox1.Height := 20; // the height of you combobox
When you add this to your form, you'll see a box pretty much the same as an TEditBox; Now, you wand to add options to your combobox. (that's where you made it for :p). To add Items to your combobox add the following to your form setup:
ComboBox1.Items.Add('Cookies');
ComboBox1.Items.Add('Pizza');
ComboBox1.Items.Add('Taco''s');
ComboBox1.Items.Add('Coca cola light');
When you run the form again, you'll see that your options are visible! Also, the same as an TEdit; the text that's in the box can be found with:
ComboBox.Text := 'Insert food here';
WriteLn(ComboBox1.Text);
To see an preview of the ComboBox in an working form:
var
frmDesign: TForm;
Button1: TButton;
Label1: TLabel;
ComboBox1: TComboBox;
Procedure ButtonClick(Sender: TObject);
Begin
frmDesign.ModalResult:= mrOk;
ShowMessage('You like ' + ComboBox1.Text + ' the most!'); // here you see that it will call your name, wich you putted in the TEdit;
End;
procedure InitForm;
begin
{ The TForm; part }
frmDesign := CreateForm;
frmDesign.Left := 100;
frmDesign.Top := 100;
frmDesign.Width := 500;
frmDesign.Height := 100;
frmDesign.Caption := 'Test!';
frmDesign.Color := ClWhite;
frmDesign.Font.Color := ClBlack;
frmDesign.Font.Name := 'Comic Sans MS';
{ The TButton; part }
Button1 := TButton.Create(FrmDesign);
Button1.Parent := FrmDesign;
Button1.Left := 375;
Button1.Top := 30;
Button1.Height := 20;
Button1.Width := 100;
Button1.Caption := 'OK';
Button1.OnClick := @ButtonClick;
{ The TLabel; Part }
Label1 := TLabel.Create(FrmDesign);
Label1.Parent := FrmDesign;
Label1.Top := 10;
Label1.Left := 10;
Label1.Caption := 'What do you like most?';
{ The TComboBox; Part }
ComboBox1 := TComboBox.Create(FrmDesign); // This will create the combobox. Must be called.
ComboBox1.Parent := FrmDesign; // without this your combobox wont be visible
ComboBox1.Top := 30; // how many pixels from the top
ComboBox1.Left := 10; // how many pixels from the left
ComboBox1.Width := 350; // the width of your combobox
ComboBox1.Height := 20; // the height of you combobox
ComboBox1.Items.Add('Cookies');
ComboBox1.Items.Add('Pizza');
ComboBox1.Items.Add('Taco''s');
ComboBox1.Items.Add('Coca cola light');
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.
The last thing you should know about TComboBoxes is how to clear the option items. You remove all your added items with the following code:
ComboBox1.Clear;
Congratulations! You now know how to add ComboBoxes to your form!
Advanced TComboBox;
The advanced stuff of a TComboBox, is actually the same as the TEdit. You can limit users in what to put in the ComoBox. Scar has the following properties:
.MaxLength := 4;
The user will not be able to put more then 4 chars in your combobox now. Useful for Players[].Pin for example.
.PasswordChar := '*';
This is very useful to hide passwords! if you type: P@SSW0RD, you will only see "********", but when you get the text of your box (string := Edit.Text) you'll get P@SSW0RD again :)
FAQ TComboBox;
no questions yet.
End of TComboBox;
MasterKill
02-01-2009, 07:32 PM
TListBox;
The following might sound a bit obvious, but I can't give it an other discription. A TListBox is a box with non-user-edit able items in it. But the great thing is, that you can make a onclick procedure after the box, and preform an action when a item in the list is clicked. Or you can just use it to load your "last saved progress report" in for example. We will start of with the basic creating, then how to add a report in it, then how to make the onclick work.
And of course you'll first need to add the box to your global vars:
Var
List1: TListBox;
And this to actual create the list in your form:
List1 := TListBox.Create(FrmDesign); // This creates the ListBox. Must be called
List1.Parent := FrmDesign; // Without this set to the form the list wont be vissible
List1.Top := 30; // how many pixels from the top
List1.Left := 10; // how many pixels from the left
List1.Width := 250; // whats the width of your list?
List1.Height := 220; // whats the height of your list?
There we have our list. Nice and empty. So now, lets say you want to add a progress report to your list. You'll have to add the following to your form setup:
List1.Items.Add('MasterKills form tutorial!');
List1.Items.Add('');
List1.Items.Add(' helped much people.');
And now, you see in your list the lines you added when you run the form.
If you make the list longer then the hight is, don't worry, a scrollbar will appear.
The last basic thing you need to know is how to make the list empty again if needed. You do that by simply adding .Clear;
List1.Clear;
Now, on how to see on what Item you clicked at your list, you need to add the onclick procedure.
Add this above your form setup:
Procedure ListClick(Sender: TObject);
Begin
End;
And this in your form setup:
List1.OnClick := @ListClick;
That will call procedure ListClick when you clicked on it. Now, to know what item of the list you clicked, you have List1.ItemIndex;. this variable contains the integer of the selected item in the list. If nothing is selected it will result -1; To see what you clicked you add this code to your ListClick procedure:
ShowMessage('You clicked at item: ' + IntToStr(List1.ItemIndex));
Congratulations! You now know how to add a list to your form!
An other example of a working list:
var
frmDesign: TForm;
Label1: TLabel;
List1: TListBox;
Procedure ListClick(Sender: TObject);
Begin
Label1.Caption := 'Last clicked box item: ' + IntToStr(List1.ItemIndex);
End;
procedure InitForm;
begin
{ The TForm; part }
frmDesign := CreateForm;
frmDesign.Left := 100;
frmDesign.Top := 100;
frmDesign.Width := 300;
frmDesign.Height := 300;
frmDesign.Caption := 'Test!';
frmDesign.Color := ClWhite;
frmDesign.Font.Color := ClBlack;
frmDesign.Font.Name := 'Comic Sans MS';
{ The TLabel; Part }
Label1 := TLabel.Create(FrmDesign);
Label1.Parent := FrmDesign;
Label1.Top := 10;
Label1.Left := 10;
Label1.Caption := 'Last clicked box item:';
{ The TListBox; Part }
List1 := TListBox.Create(FrmDesign); // This creates the ListBox. Must be called
List1.Parent := FrmDesign; // Without this set to the form the list wont be vissible
List1.Top := 30; // how many pixels from the top
List1.Left := 10; // how many pixels from the left
List1.Width := 250; // whats the width of your list?
List1.Height := 220; // whats the height of your list?
List1.Items.Add('first info line');
List1.Items.Add('second info line');
List1.Items.Add('third info line');
List1.OnClick := @ListClick;
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.
Advanced TListBox;
under construction
FAQ TListBox;
no questions yet.
End of TListBox;
MasterKill
02-01-2009, 07:33 PM
TImage
TImage is a fun one, It allows you to place a picture in your form. Or at least, that is the part I'll teaching you.
To start, add the TImage var to your script, BUT, you also have to add some other variables to your form. You need 3 integers to make your image work. We will add b, w and h.
Var
Image1: TImage;
b, w, h: Integer;
now, get the image you want to put into your form.
To add the image to your form add this to your form setup:
Image1 := TImage.Create(FrmDesign);
Image1.Parent := FrmDesign;
Image1.Left := 20;
Image1.Top := 20;
Image1.Width := {width of your image};
Image1.Height := {height of your image};
b := loadbitmap({Location of your file as a string! (C:\Program Files\?? ect...});
getbitmapsize(b, w, h);
copycanvas(getbitmapcanvas(b), Image1.canvas, 0, 0, w, h, 0, 0, w, h);
When you have done this, and replaced the {...} stuff with what should be there, try to run the form and you'll see your image in the form :)
Congratulations! You now know how to add a picture to your form!
If you think the standard colored background of your form is boring, you could make a TImage as background! If you want to use a TImage as background, your form setup order should be like this:
First setup your TForm; Then setup your TImage for the background Then setup all your other buttons, labels, edits, ect ect.
Advanced TImage;
under construction
FAQ TImage;
no questions yet.
End of TImage;
MasterKill
02-01-2009, 07:34 PM
TTimer;
http://img7.imageshack.us/img7/382/ttimeraz1.gif
A TTimer, as you can see in the image above, a TTimer will call a function every set amount of time. This can be usefull for for changing the image of you form every few seconds, count up/down, and lots of other stuff. In this part of the tutorial I'm going to learn you how to make a TTimer, and how to make good use of it.
The first thing you should know, a TTimer is not visible.
Lets add the var to the script:
Var
Time1: TTimer;
Since your TTimer is not visible, you don't have to set the width, height, top, left and the parent. But there are a few other things you have to call in your form setup:
Timer1 := TTimer.Create(FrmDesign); // This will create your timer. Must be called.
Timer1.Interval := 1000; // After how many mili-seconds must your procedure be called?
Timer1.OnTimer := @OnTimer; // Do what procedure if your timer is ready?
Timer1.Enabled := True; // Active timer? True for yes.
As you might already have noticed: The timer wants to call a procedure. So lets make it! Place this ABOVE your form setup :)
Procedure OnTimer(Sender: TObject);
Begin
WriteLn('Hello!');
End;
When you run your script, you'll see that every second a new "Hello!" will be added to your debug :D
Note: when you close your form, the Timer WILL NOT STOP. So, after your form, you should call:
Timer1.Enabled := False;
That will deactivate your timer and your script can play.
Important:
Do never add a mouse movement in your TTimer procedure. You script will crash if scar has to do 2 mouse movements at the same time. Make sure you stop the timer once the form is closed.
Another TTimer preview:
var
frmDesign: TForm;
Timer1: TTimer;
Label1: TLabel;
Count: Integer; // This variable will be used for the counting!
Procedure OnTimer(Sender: TObject);
Begin
Count := Count + 1;
Label1.Caption := 'Form is allready open for: ' + IntToStr(Count) + ' seconds.'; // this is where it updates the labels text when the button is pressed.
End;
procedure InitForm;
begin
{ The TForm; part }
frmDesign := CreateForm;
frmDesign.Left := 100;
frmDesign.Top := 100;
frmDesign.Width := 500;
frmDesign.Height := 100;
frmDesign.Caption := 'Test!';
frmDesign.Color := ClWhite;
frmDesign.Font.Color := ClBlack;
frmDesign.Font.Name := 'Comic Sans MS';
{ The TButton; part }
Timer1 := TTimer.Create(FrmDesign);
Timer1.Interval := 1000;
Timer1.Enabled := True;
Timer1.OnTimer := @OnTimer;
{ The TLabel; Part }
Label1 := TLabel.Create(FrmDesign);
Label1.Parent := FrmDesign;
Label1.Top := 10;
Label1.Left := 10;
Label1.Caption := 'Form is allready open for: 0 seconds.';
Label1.Font.Size := 18;
Label1.Font.Color := ClRed;
Label1.Font.Name := 'Comic Sans MS';
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.
Advanced TTimer;
under construction
FAQ TTimer;
no questions yet.
End of TTimer;
MasterKill
02-01-2009, 07:35 PM
Create a player setup form
Designers stage
Before you are going to make your form, you need to have an idea of what your form is going to look like. Make a concept in MSPaint. Why first make a concept? This is to make sure you don't forget anything. (once I forgot to add a TEdit; for the "loads till switch" option in the form and it takes a lot of time to add it in again once your form was done already).
For this tutorial I made this concept, and this is what it should look like in the end:
http://img398.imageshack.us/img398/2161/formdesignid1.png
Working out your design
Now it's time to start making the player form. This is going to the longest part of the tutorial. I'll number the steps were doing, so you can see where you where.
In this tutorial I'm not going to post the complete code over and over again from what we got now. You should be able yourself to add the new code to your script. I will post the complete script at the end of the tutorial, so if you really can't find out what's going wrong, you can take a look at it. Or you could just post something here ;)
The first thing where going to do, is make the base, the TForm (http://www.villavu.com/forum/showthread.php?t=41418?p=538449#post538449) with his standard code. We will give the form a Height*Width of 800*600. You should not make your form much bigger because there are people who don't have a big screen. Yes this might be to large, but we will get rid of the left over space once the complete form design is done.
var
frmDesign: TForm;
procedure InitForm;
begin
frmDesign := CreateForm;
frmDesign.Left := 100;
frmDesign.Top := 100;
frmDesign.Width := 800;
frmDesign.Height := 600;
frmDesign.Caption := 'Test!'; // Rename to whatever you want
frmDesign.Color := ClWhite;
frmDesign.Font.Color := ClBlack;
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 ShowPlayerForm;
begin
SafeInitForm;
SafeShowFormModal;
end;
{In your script you just have to call ShowPlayerForm;}
Begin
ShowPlayerForm;
End.
http://img27.imageshack.us/img27/6208/formimage1smallah6.png (http://img228.imageshack.us/img228/3324/formimage1bc2.png)
Now we are going to add items to our form. We will start of with the TListBox (http://www.villavu.com/forum/showthread.php?t=41418?p=538461#post538461). Why not the banner first? That is because we don't know the width of our form yet, and so also not from the banner. Since we only have 1 TListBox, we don't have to put it in an array. So lets add it to our global variables, at the top of our script.
Var // and also your TForm will be in this variable list obviously
PlayerList: TListBox;
Now, to create the listbox in your form. We will set the .Top to 120, because we need to keep some space for banner, wish we will make later.
PlayerList := TListBox.Create(FrmDesign);
PlayerList.Parent := FrmDesign;
PlayerList.Top := 120;
PlayerList.Left := 10;
PlayerList.Width := 100;
PlayerList.Height := 170;
PlayerList.OnClick := @ItemClicked;
When you have added that to your form, you'll notice your script wont work. That's true, because we don't have the ItemClicked procedure yet. We are going to use the same .OnClick procedure for every OnClick we will get.
We do that as the following for our PlayerList:
Procedure ItemClicked(Sender: TObject);
Begin
Case Sender Of
PlayerList: Begin
// leave it empty for now
End;
End;
End;
Make sure you place the procedure above the form setup.
When you click on the PlayerList in the form, nothing will happen, and the list is empty. We will leave it that way for now, because we first want to make all components are in the right place.
http://img89.imageshack.us/img89/7571/formimage2smallwz9.png (http://img84.imageshack.us/img84/5665/formimage2ad9.png)
The next thing we are going to add to our form, are the buttons (http://www.villavu.com/forum/showthread.php?t=41418?p=538451#post538451). Since we have 7 buttons, we will put the TButton in an array, to keep our code short and easy over viewable.
So we are going to add three variables to the global vars.
The button array (0 til 6)
An integer for the loop
A string array for the button captions
That will look like the following:
Var
Buttons: Array [0..6] Of TButton;
I: Integer;
CaptionA: Array Of String;
Lets move on to the setup of the buttons in the form. We will use a For To Do loop, to do all the buttons. There will be 2 lines of buttons. The line at the right of the ListBox, and a line horizontal under the ListBox. We are not going to set the button position for every button, we will use a small formula instaid.
CaptionA := ['Load player list', 'Save player list', 'Add player',
'Delete player', 'Start script', 'Exit without saving', 'Save and Exit'];
For I := 0 To 6 Do // See*
Begin
Buttons[I] := TButton.Create(FrmDesign);
Buttons[I].Parent := FrmDesign;
Buttons[I].Height := 20;
Buttons[I].OnClick := @ItemClicked;
Buttons[I].Caption := CaptionA[I];
Case I Of
0..3: Begin // case 0, 1, 2, 3
Buttons[I].Left := 120;
Buttons[I].Top := 150 + I * 30;
Buttons[I].Width := 100;
End;
4..6: Begin // case 4, 5, 6
Buttons[I].Left := 10 + 160 * (I - 4); // See**
Buttons[I].Top := 300;
Buttons[I].Width := 150;
End;
End;
End;
* With this loop the script will first setup button[0], then button[1], ect, until button[6].
** Why the -4? else the .Left of Buttons[4] will be: 10 + 160 * 4, and then the button would be way to much to the right. So don't forget the -4
The code above will take care of ALL your buttons. Take a very good look at the code above, and try to understand what the script exactly does.
In the setup of the button we have called at all buttons @ItemClick; as onclick procedure. To see if all your buttons work you should replace your ItemClick procedure with this:
Procedure ItemClicked(Sender: TObject);
Begin
Case Sender Of
PlayerList: Begin
// keep empty for now
End;
Buttons[0]: Begin
WriteLn(' Load players');
End;
Buttons[1]: Begin
WriteLn('[BUTTON] Save players');
End;
Buttons[2]: Begin
WriteLn('[BUTTON] Add player');
End;
Buttons[3]: Begin
WriteLn('[BUTTON] Delete player');
End;
Buttons[4]: Begin
WriteLn('[BUTTON] Start script');
End;
Buttons[5]: Begin
WriteLn('[BUTTON] Stop without save');
End;
Buttons[6]: Begin
WriteLn('[BUTTON] Stop but save first');
End;
End;
End;
When you run your script again, you will see that the debug says what you clicked when you click on a button.
http://img5.imageshack.us/img5/7808/formimage3smallfb9.png (http://img3.imageshack.us/img3/7125/formimage3ey4.png)
We are going to make 1 button working already. The "Exit without save" button. We need this button working because we are going to remove the "Frame" of the form (the frame where you can close the form, mini and maxi size it).
Before we do that we are going to add a new variable to your script:
Var
StartReady: Boolean;
We need this variable to let the script know when the start button is pressed, cause if the start button is not pressed, but one of the exit buttons, the script should terminate after closing the form.
Lets go to [B]Procedure ShowPlayerForm; and change it to this:
Procedure ShowPlayerForm;
begin
SafeInitForm;
SafeShowFormModal;
If Not StartReady Then TerminateScript;
end;
This action is very important.
Now, before removing the forms frame, we are going to make the "Exit without save" working. Go to your ItemClick procedure, and change Button[5] to This:
Buttons[5]: Begin
frmDesign.ModalResult:= mrOk; // this will close the form
End;
When you run your form again, you'll see that the form closes when you press the button. We can remove the forms frame now, and you'll still be able to close the form.
Add this to your form setup:
frmDesign.BorderStyle := bsNone;
Now you successfully removed the frame. Now, since the background color of the form is white, it won't be good visible. So we will change the forms background color to red. This might be ugly, but later in the tutorial we will add a image as background, wish will give you form an amazing look.
Change the background color of your form to red:
frmDesign.Color := ClRed;
Now, we also know the height of our form already! we can shorten the height of your form so all that extra space won't be there anymore, since we are not going to use it. I can tell you the form height should be "330" now, don't make it any less, cause some of your buttons won't be visible anymore! (If you did it anyway you can close your form by pressing ALT+F4). So lets change the forms height to 330:
frmDesign.Height := 330;
http://img5.imageshack.us/img5/2659/formimage4smalles7.png (http://img99.imageshack.us/img99/6923/formimage4vc2.png)
In this step we are going to add the labels (http://www.villavu.com/forum/showthread.php?t=41418?p=538452#post538452) to the form. The labels will tell the user what to put in the box next to it. We need to make 8 labels. So we will make an array from 0 to 7. Add this to your vars:
Var
Labels: Array [0..7] Of TLabel;
We will also need I and CaptionA again, but we don't have to declare them again in the global vars, since there already in there.
Lets create the labels in your form:
CaptionA := ['Players name', 'Players pass', 'Players nick', 'Players Pin',
'Loads till switch', 'Use this player?', 'SRL ID', 'SRL Pass'];
For I := 0 To 7 Do // See*
Begin
Labels[I] := TLabel.Create(FrmDesign);
Labels[I].Parent := FrmDesign;
Labels[I].Caption := CaptionA[I];
Case I Of
0..5: Begin
Labels[I].Top := 120 + 30 * I;
Labels[I].Left := 230;
End;
6, 7: Begin
Labels[I].Top := 180 + 30 * (I - 6); // See**
Labels[I].Left := 450;
End;
End;
End;
* the loop will do Labels[1], then Labels[2], ect, until Labels[7]
** Again don't forget to do the -6, else it won't be at the correct position
And actually that's all about the labels :)
http://img218.imageshack.us/img218/8302/formimage5smallfk4.png (http://img3.imageshack.us/img3/9461/formimage5nt1.png)
Then it's time to add the edit boxes (http://www.villavu.com/forum/showthread.php?t=41418?p=538458#post538458)! We will make 6 TEdits. Why not 8? cause for the "players.active" and the "players.loads" we are going to use a TComboBox. But we will start of making the TEdits now.
So we are going to make 6 TEdit's, that will make it an array form 0 to 5:
Var
Edits: Array [0..5] Of TEdit;
Then, to create your editboxes in your form, add this to your form setup:
For I := 0 To 5 Do
Begin
Edits[I] := TEdit.Create(FrmDesign);
Edits[I].Parent := FrmDesign;
Edits[I].Width := 100;
Edits[I].Height := 20;
Case I Of
0..3: Begin
Edits[I].Left := 340;
Edits[I].Top := 120 + 30 * I;
End;
4, 5: Begin
Edits[I].Left := 540;
Edits[I].Top := 180 + 30 * (I - 4); // See*
End;
End;
End;
Edits[1].PasswordChar := '*'; // See **
Edits[3].PasswordChar := '*';
Edits[5].PasswordChar := '*';
Edits[2].MaxLength := 4; // See***
Edits[3].MaxLength := 4;
* Again, don't forget the -4
** with this other people can't see your password, except for "password" they will see "********"
*** People's nickname should not be longer then 4, and there pin can be max 4 numbers
Checkout the PasswordChar and MaxLength. Those are really cool tools to make your form more user friendly and better. We don't have to do anything more to those :)
http://img27.imageshack.us/img27/6586/formimage6smallmq6.png (http://img25.imageshack.us/img25/1990/formimage6ub0.png)
We can already see what the width of the form should be, but before we are going to edit that we will add the TComboBoxes (http://www.villavu.com/forum/showthread.php?t=41418?p=538460#post538460) first.
2 empty spots in the form, so we are going to make an array form 0 to 1 in your global vars:
Var
ComboBoxes: Array [0..1] Of TComboBox;
And to create your ComboBoxes in the form, add this to your form setup:
For I := 0 To 1 Do
Begin
ComboBoxes[I] := TComboBox.Create(FrmDesign);
ComboBoxes[I].Parent := FrmDesign;
ComboBoxes[I].width := 100;
ComboBoxes[I].Height := 20;
ComboBoxes[I].Left := 340;
ComboBoxes[I].Top := 240 + 30 * I;
End;
ComboBoxes[0].Items.Add('3'); // adding options to your combobox
ComboBoxes[0].Items.Add('4');
ComboBoxes[0].Items.Add('5');
ComboBoxes[0].Items.Add('6');
ComboBoxes[0].Items.Add('7');
ComboBoxes[1].Items.Add('True');
ComboBoxes[1].Items.Add('False');
Adding items to your boxes takes some space, but it's not worth putting those in an array ;)
And that's already it for the combo boxes!
http://img218.imageshack.us/img218/2783/formimage7smallkn8.png (http://img25.imageshack.us/img25/6910/formimage7hm1.png)
Yesss, it's allmost time to get our banner, and to get rid of that ugly red background! But before we are going to do that we need to fix the width of your form.
Edit this in your form setup:
frmDesign.Width := 650;
Perfect! you now also know what the width and height of your banner and background should be!
Banner: 630 * 100
Background: 650 * 330
http://img5.imageshack.us/img5/3060/formimage8smalloz7.png (http://img98.imageshack.us/img98/4817/formimage8dn8.png)
In this step, we will give your form a very nice look! Before we are going to add any code, we need to have our images ready. One for the background, and one for the banner. I Made those 2 already for this tutorial, but feel free to make your own.
Go to your scar folder, and create a new folder. We are going to call it "MKFormTut". Now, in your new map you'll have to save your 2 files. I'll call them "formbanner1.bmp" and "formbackground.bmp".
formbackground.bmp (http://img218.imageshack.us/img218/9343/formbackgroundnu1.png)
formbanner1.bmp (http://img218.imageshack.us/img218/4227/formbannerih2.png)
Make sure you save them in the correct folder. If your not sure where to exactly where to save them you can run this small script in a new scar:
Begin
ClearDeBug;
WriteLn(AppPath + 'MKFormTut\');
WriteLn('');
End.
Now, we are going to add the images to the global vars. We have 2 images so an array from 0 to 1:
Var
Images: Array [0..1] Of TImage;
Before we start adding the images to the form, we have 3 new variables to add. b, w, h: integer;. Since we only need those 3 vars in the form setup, we will add the variables to the setup form procedure:
procedure InitForm;
Var
b, w, h: Integer;
begin
// ect
Now it's time to add the images to the form setup. NOTE: the images must be declared between the TForm and the First other object (the TListBox in this case)! Here we go:
// TForm setup is here
For I := 0 To 1 Do
Begin
Images[I] := TImage.Create(FrmDesign);
Images[I].Parent := FrmDesign;
Case I Of
0: Begin
Images[I].Width := 650;
Images[I].Height := 330;
b := loadbitmap(AppPath + 'MKFormTut\formbackground.bmp'); // See*
getbitmapsize(b, w, h);
copycanvas(getbitmapcanvas(b), Images[I].canvas, 0, 0, w,
h, 0, 0, w, h);
End;
1: Begin
Images[I].Width := 630;
Images[I].Height := 100;
Images[I].Left := 10;
Images[I].Top := 10;
b := loadbitmap(AppPath + 'MKFormTut\formbanner1.bmp'); // See*
getbitmapsize(b, w, h);
copycanvas(getbitmapcanvas(b), Images[I].canvas, 0, 0, w,
h, 0, 0, w, h);
End;
End;
End;
// all other TObjects are here
* If you gave it an other name, then set it to the other name of cause.
... ect
Your form must look awesome now! If your not happy with your background, just change the bmp file and restart the script to see the new background/banner.
http://img145.imageshack.us/img145/4937/formimage9smallgy4.png (http://img145.imageshack.us/img145/7438/formimage9bz7.png)
Then, it's time to add our TTimer, because we don't want to bore people with the same banner all the time :)
I made some more banners to add to our form:
banner1 (http://img5.imageshack.us/img5/976/pcbannerju9.png)
banner2 (http://img6.imageshack.us/img6/8113/srlbanneryj3.png)
banner3 (http://img4.imageshack.us/img4/6103/ownbannerkg3.png)
Name them to whatever you want. But make sure you save them in your own folder. For this tutorial they need to come in your MKFormTut\ folder.
First of this step, we are going to add the timer to your script. We will need the timer to change the banner images. Add the TTimer to your global vars:
Var
BannerTimer: TTimer;
And now, setup the timer in your form setup:
BannerTimer := TTimer.Create(FrmDesign);
BannerTimer.Interval := 5000; // See*
BannerTimer.Enabled := True; // See**
BannerTimer.OnTimer := @ItemClicked; // See***
* We want our banner to change every 5 seconds
** Activate your timer
*** ItemClicked also works for your timer, so why not use it?
Now we have our timer working, nothing is happening yet though. True, so lets change that! We will need a new global var so the script can remember wish banner it should display next:
Var
CurBanner: Integer;
We also need to add the, b, w and h again. This time we will add it tho the ItemClicked procedure:
Procedure ItemClicked(Sender: TObject);
Var
b, h, w: Integer;
Then, lets add the BannerTimer, to the case in ItemClicked:
Case Sender Of
BannerTimer: Begin
Case CurBanner Of // See*
0: b := loadbitmap(AppPath + 'MKFormTut\pcbanner.bmp'); // See**
1: b := loadbitmap(AppPath + 'MKFormTut\srlbanner.bmp');
2: b := loadbitmap(AppPath + 'MKFormTut\ownbanner.bmp');
3: b := loadbitmap(AppPath + 'MKFormTut\formbanner.bmp');
End;
getbitmapsize(b, w, h);
copycanvas(getbitmapcanvas(b), Images[1].canvas, 0, 0,
w, h, 0, 0, w, h);
CurBanner := CurBanner + 1; // See***
If CurBanner > 3 Then CurBanner := 0; // See****
End;
// and here are your other clickitems
* For B we need to load the current bitmap, to display as banner.
** Make sure your file is at the correct space, and change the name to what you called your banner
*** To display the next banner next time, you need to add 1 to the current banner.
**** The script can't display a banner that doesn't exists. So when you had your last banner we will go back to banner 0
And there you go! Changing banners! Awesome!
http://img132.imageshack.us/img132/8469/formimage10gifsmalltx5.gif (http://img5.imageshack.us/img5/6927/formimage10gifrt7.gif)
Congratz! You now have the base of an awesome looking form!
You have completed the look of your form, and you have all the TComponents you need. Now it's time to make it work, and let the form actually do something!
The first thing we are going to make work is the Add new player button. And with this step there comes a lot more then just the button's procedure. You see, all the players in your form, must be stored, in an array. An array wish holds all the info from the player setup boxes for all players created in the from :)
We are going to make an array of TFormPlayer. TFormPlayer? is that correct? Yes, but it doesn't exist yet. Lets make a new type, and so create the TFormPlayer variable
Type
TFormPlayer = Record
Name, Pass, Nick, Pin, Loads, Active: String;
End;
So, for every box you have in your form, you add a string to your new Type. (or at least for what every player needs to have)
Lets make a new variable: FP (form players) Add it to your global vars. We also want to add the variable "CurFP: Integer;". This one is there for the form to know what player it's showing at that moment.
CurFP: Integer;
FP: Array Of TFormPlayer;
Now, we have the stuff where we can store all players in your form. We will later convert it to Players[].Name, ect.
We have made the new array for all of the players now. When we start the form, we want to have at least one player already. So we go to your ShowPlayerForm; procedure, and add the following to it:
Procedure ShowPlayerForm;
begin
SetArrayLength(FP, 1); // *
SafeInitForm;
SafeShowFormModal;
If Not StartReady Then TerminateScript;
end;
* Now we have one player, so the form is ready to store the new player strings in that FP part.
The FP part is done! Now it's time to make the AddPlayerButton work.
When a users hits the add player button, we simply have to add a new part to the FP array. We do that by making the length of the array bigger.
Jump to your ItemClicked procedure. There we have to work on our Add Player part. Within the add player case we are going to add this:
Buttons[2]: Begin
SetArrayLength(FP, GetArrayLength(FP) + 1);
End;
* This will add a new player to your FP array, and gives you space for another form player.
** We need to let the form know, that we are going to edit the latest and newest player.
Yay, now every time, you click the "add player button", you add a new player to your FP array! yaaaaaaaaaaaaaaaaaaay!
But wait, nothing seems be happening? That's not true. We just need to visualize it. And that's where we are going to make the LoadPlayer(); procedure for. To finnish your "AddNewPlayer" button, we add this to your code:
Buttons[2]: Begin
SetArrayLength(FP, GetArrayLength(FP) + 1);
LoadFP(High(FP), True); // *
End;
* Yes, you have an error now, and if you want to fix that you better hurry to step 12! :)
YES! It's time we actually make the big major procedure! Procedure LoadFP();! This is the place where all your player info gets loaded, and saved into the FP array. And most important of all, here will all your stuff get visualized!
What this procedure is going to do is:
Save your player info form your latest edit
Load the players info of the player you want to edit now
Show in the listbox all your players
Show all the players data in the form for the current player (CurFP)
This procedure is the key to everything in your code.
So the first thing we are going to do, is create the new form procedure: (make sure you create it above the ItemClicked procedure)
Procedure LoadFP(WhatPlayer: Integer; SaveCurrentInfo: Boolean);
Begin
End;
As you can see I have added 2 variables in the procedure. WhatPlayer; this is the integer the script need of wish player it has to load this time. SaveCurrentInfo; Does the script want to save the info of the player wish is currently displayed.
When you have created this procedure you'll see that your script has no errors anymore ;) And that makes it time to make the procedure actually do something.
The first thing the scripts need to do, is to save the current player, before we change all the boxes, else it won't saved correctly, or just not saved at all. We start with the following code:
If SaveCurrentInfo Then
Begin
FP[CurFP].Name := Edits[0].Text;
FP[CurFP].Pass := Edits[1].Text;
FP[CurFP].Nick := Edits[2].Text;
FP[CurFP].Pin := Edits[3].Text;
FP[CurFP].Loads := ComboBoxes[0].Text;
FP[CurFP].Active := ComboBoxes[1].Text;
End;
Now we are sure new player info has been saved and we can start loading an other player! The first thing I would like to do is giving the TListBox an update, so users can overview there players when changes are made. We do that by first clearing the box, and then loading the player list in again:
Var
I: Integer; // add this at the top of the procedure!
// add this below the save player (in LoadFP)
PlayerList.Clear;
For I := 0 To High(FP) Do
If (FP[I].Name = '') Then
PlayerList.Items.Add(IntToStr(I) + ': ?')
Else
PlayerList.Items.Add(IntToStr(I) + ': ' + FP[I].Name);
That will show a clear list of your players, numbered and players without a name yet will get a "?".
The next step in LoadFP is that we need to load in the player we want to see now. We will fill the Edits and ComboBoxes up with the new CurFP:
CurFP := WhatPlayer;
PlayerList.ItemIndex := CurFP; // *
Edits[0].Text := FP[CurFP].Name;
Edits[1].Text := FP[CurFP].Pass;
Edits[2].Text := FP[CurFP].Nick;
Edits[3].Text := FP[CurFP].Pin;
ComboBoxes[0].Text := FP[CurFP].Loads;
ComboBoxes[1].Text := FP[CurFP].Active;
* Here we highlight the new CurFP in the listbox
The last, but also very important thing, is to disable the "delete player" button, when there are less then 2 players. This is to prevent out of range errors, because you can't delete players if they don't exist. We will make a check like this:
Buttons[3].Enabled := (GetArrayLength(FP) > 1);
That line might look a bit weird, but this is what it does: When there is more then 1 form player, it will enable the delete button, if there is only one, it will disable it.
Congrats! LoadFP should be done for now! But you might have noticed, when you click the "add player" button you have 2 players? That's correct, because you already had one when you loaded the form, but you didn't see it yet. To fix this you'll have to add this at the bottom of your InitForm; procedure:
LoadFP(0, False);
OnClick PlayerList
When a user clicks on a char's name in the player list, the form should load in that player right after his name has been clicked. We can do this very very easily (thanks to LoadFP() <3 <3 <3).
Go to your ItemClicked() procedure, there you find the onclick for PlayerList:. When a users clicks on a name, the PlayerList.ItemIndex will change to the array number of the clicked item in the list. Since the player names and positions in the player list perfectly match, we can just use that value for LoadFP:
PlayerList: Begin
LoadFP(PlayerList.ItemIndex, True);
End;
And as you see above, the safe value is true, we don't want edited player info to get lost.
Delete player
Omg I made a bullshit player and I want it out of my list. THAT'S POSSIBLE, with the delete button. This button has a very nasty peace of code, and it might be hard to understand, but I will try to explain it as good as I can.
When you are going to delete a player, the FP array needs to get smaller. When you want to delete the last player of the list, it's simple. Just say HowMany FP = -1. But what if you want to delete player 3 of 5? Then there will be a gap in your array, so this is how it's done to prevent gap's like that:
To remove player 3 of 5, you need to move player 4 to position 3, and player 5 to position 4. This will remove player 3 without making a gap. When you've moved all players after the player you want to delete, you can make the array smaller, with SetArrayLenght(-1).
So in our delete player procedure we have 3 situations:
situation 1. The player you want to delete is the last player of the list.
situation 2. The player you want to delete is the last BUT 1 player of the list.
situation 3. The player you want to delete has 2 or more charterers after it.
We have to make the delete button work with all these 3 situations, and they will all work a little bit different!
I'll show you the source of how it's done (very short but powerfull code):
Buttons[3]: Begin
//WriteLn('[BUTTON] Delete player');
If Not (CurFP = High(FP)) Then // *
If (CurFP + 1 = High(FP)) Then
FP[CurFP] := FP[High(FP)] // **
Else
For I := CurFP To High(FP) - 1 Do // ***
FP[I] := FP[I + 1];
SetArrayLength(FP, GetArrayLength(FP) - 1); // ****
LoadFP(High(FP), False); // *****
End;
[b]* When the case is situation 1, we don't have to peform any actions yet, we will just have to remove 1 player at the end of the procedure.
** When the case is situation 2, we have to switch the last player, to the "last but one" position! After that we can remove the last player at the end of the procedure.
*** When the case is situation 3, we have to switch all players, after the CurFP, a place back in the array. After that we can remove the last player at the end of the procedure.
**** This is where you say to your array, remove the last player of the array. This is fine to do now, since you have switched all your players in the array already.
***** After you have removed a player, your form has to load an other player and update the PlayerList! we do that with LoadFP() <3
As I said above, the procedure might be very hard to understand. If you still don't get anything, feel free to PM me or make a post in this thread.
The probably, most important button of the script! THE START BUTTON! MUAHAHAHA.
AT THIS POINT ADD {.include srl\srl.scar} TO YOUR SCRIPT!
You might have noticed, that all the players are now saved in FP[], all in strings. What we need to do now is to convert all strings into the SRL Players[] stoof! We have to convert the FP[].Name to Players[].Name, but also stuff like: FP[].Loads (STRING) to Players[].Integers[] (INTEGER). And that can't be done with some error checking, since you cannot convert the string "I would like to do 8 loads please" to the integer 8.
When you click the start button, the script will loop trough all your players, checking for a correct setup. This will be very user and script friendly. For example: when you forgot to fill in your players nickname at player number 3, the script will load player 3 for you and say "oops, it seems like you forgot player 3 his nick!". To do this for all players and there subs like "name, nick, ect", will take some space of code, but, in trade for that it will result a very nice user friendly script.
Before you start you have to save your current player. You just add "LoadFP(CurFP, True);" to the begin of your OnStartClick. we also need to set the length of your of players[] already. We do that like this:
Note that the script does do nothing with the srl stats boxes, this is because the srl stats system is currently down, and I'll update it when it's back
Buttons[4]: Begin
//WriteLn(' start script');
LoadFP(CurFP, True);
SetArrayLength(Players, GetArrayLength(FP));
For I := 0 To High(FP) Do
Begin
SetArrayLength(Players[I].Integers, 1); // *
SetArrayLength(Players[I].Strings, 0); // **
SetArrayLength(Players[I].Booleans, 1); // ***
If (FP[I].Name = '') Then
Begin
LoadFP(I, False);
ShowMessage('Oops, you forgot to give player ' + IntToStr(I) + ' a name!');
Exit;
End Else
Players[I].Name := FP[I].Name;
If (FP[I].Pass = '') Then
Begin
LoadFP(I, False);
ShowMessage('Oops, you forgot ' + FP[I].Name + ' his password!');
Exit;
End Else
Players[I].Pass := FP[I].Pass;
If (FP[I].Nick = '') Then
Begin
LoadFP(I, False);
ShowMessage('Oops, you forgot ' + FP[I].Name + ' his nickname!');
Exit;
End Else
Players[I].Nick := FP[I].Nick;
Players[I].Pin := FP[I].Pin; // no need to check
Try
Players[I].Integers[0] := StrToInt(FP[I].Loads);
Except
LoadFP(I, False);
ShowMessage('Oops, ' + FP[I].Name + ' has a wrong "loads" amoult!' +
' make sure it''s number only!');
Exit;
End;
Try
Players[I].Active := StrToBool(FP[I].Active);
Except
LoadFP(I, False);
ShowMessage('Oops, ' + FP[I].Name + ' has a wrong "active" amoult!' +
' choose an option from the drop down box!');
Exit;
End;
End;
StartReady := true;
frmDesign.ModalResult:= mrOk; // ****
End;
[B]* Very important! here you must say how many custom integers your adding to your players[]
** Very important! here you must say how many custom strings your adding to your players[]
*** Very important! here you must say how many custom booleans your adding to your players[]
**** When the script gets at this line, it means that every player was succesfully checked, and that ALL your players are now in the old Players[CurrentPlayer]. stuff! READY TO ABUSE YOUR SCRIPT! With this like the form closes and continues the script!!!!!!!!!!!!!!!!!!! THE FORM IS WORKING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!
CONGRATS!
The script is working and it should now be working with your script!
If you got a smooth result, feel free to post a screenshot and I will make sure it ends up in the "wall of fame"
Download background and banner
MasterKill
02-01-2009, 07:36 PM
Save & Load prayers into the form
Under construction
MasterKill
02-01-2009, 07:37 PM
Other components
TRichEdit;
TCheckBox;
TProgressBar;
Torrent of Flame
02-01-2009, 07:38 PM
What is this tutorial going to be on? I mean like for 12 posts? DARN!
MasterKill
02-01-2009, 07:48 PM
What is this tutorial going to be on? I mean like for 12 posts? DARN!
A huge form tutorial :) I hope I can learn people in the detail how to make a nice form. And this is prolly going to take me a week :p but i can and will finnish it ;)
NiCbaZ
02-01-2009, 08:44 PM
Nice, tho in the player section, a good thing to do is, with player loading is creating a new tab for each player... i use that and its good so you should add that, Because it would teach Tabs, and multiplayer.
Dervish
02-01-2009, 08:52 PM
Typo in post #11.
MasterKill
02-01-2009, 09:58 PM
Nice, tho in the player section, a good thing to do is, with player loading is creating a new tab for each player... i use that and its good so you should add that, Because it would teach Tabs, and multiplayer.
I use a TListBox for that ;) You'll find out how to do that once the tutorial is done xD
But thanks for you input
Typo in post #11.
LOL. care :p edited though :)
oh and i have dyslexia
Rubix
02-02-2009, 09:40 PM
would it be possible to have like check boxes like
[x] Edgeville
[ ] Varrock
[ ] Falador
MasterKill
02-03-2009, 06:08 AM
would it be possible to have like check boxes like
[x] Edgeville
[ ] Varrock
[ ] Falador
oh yes, I'll add that to the "Other components" post, and make a tutorial for it as soon as possible.
{name} :TCheckBox;
Smarter Child
02-05-2009, 07:56 PM
When finished im gonna read this whole tutorial.
Timer
02-07-2009, 03:56 PM
Holy .... MK
Torrent of Flame
02-07-2009, 04:00 PM
Where is this guys tut writer cup?!
Baked0420
02-07-2009, 04:11 PM
WOW, amazing tut. Will definitely finish reading all this, I scimmed through a lot. One thing to fix is I think here:
Timer1 := TTimer.Create(FrmDesign); // This will create your timer. Must be called.
Timer1.Interval := 1000; // After how many seconds must your procedure be called?
Timer1.OnTimer := @OnTimer; // Do what procedure if your timer is ready?
Timer1.Enabled := True; // Active timer? True for yes.
I think you meant to put how many milliseconds after interval, not how many seconds. And under TTimer, in the first paragraph, you said "I'm going to learn you how" I think you meant either "I'm going to teach you how", or "I'm going to have you learn how". Probably the first one. But this tut is amazing, I never knew how to make a form, next script I make I am going to add a form to it and learn how from this tut. Good job, Rep+.
MasterKill
02-07-2009, 04:38 PM
I think you meant to put how many milliseconds after interval, not how many seconds.
oh oops! Bad thing when a tutorial is teaching something wrong ;) Thanks for correcting me!
And thanks all! I'm still working on it and I hope to finish it soon.
Wanted
02-07-2009, 05:26 PM
Very nice now if only you knew how to reduce all that code by about 300% using with do for do and arrays
{************************************************* ******************************
Form variables
************************************************** *****************************}
var
ComboBoxes: array[0..1] of TComboBox;
CheckBoxes: array[0..4] of TCheckBox;
Buttons: array[0..4] of TButton;
Labels: array[0..13] of TLabel;
Edits: array[0..5] of TEdit;
BackgroundPicture: LongInt;
CharsFileString: string;
StartScript: Boolean;
Form: TForm;
{************************************************* ******************************
procedure DeclareFormFromPlayers(I: LongInt);
By: IceFire908.
Description: Declares the settings from the SRL player array into the form.
************************************************** *****************************}
procedure DeclareFormFromPlayers(I: LongInt);
var
II: Byte;
begin
try
if (Players[I].Name <> '') then
Edits[0].Text := Players[I].Name
else
Edits[0].Text := 'New Username';
if (Players[I].Pass <> '') then
Edits[1].Text := Players[I].Pass
else
Edits[1].Text := 'New Password';
if (Players[I].Nick <> '') then
Edits[2].Text := Players[I].Nick
else
Edits[2].Text := 'New Nickname';
if (Players[I].Skill <> '') then
ComboBoxes[1].Text := Players[I].Skill
else
ComboBoxes[1].Text := 'Agility';
CheckBoxes[0].Checked := Players[I].Active;
if (Players[I].Strings[0] <> '') then
Edits[3].Text := Players[I].Strings[0]
else
Edits[3].Text := '0000';
if (Players[I].Strings[1] <> '') then
ComboBoxes[0].Text := Players[I].Strings[1]
else
ComboBoxes[0].Text := '[Air] (FEB)';
Edits[4].Text := IntToStr(Players[I].Integers[0]);
Edits[5].Text := IntToStr(Players[I].Integers[1]);
for II := 1 to 4 do
CheckBoxes[II].Checked := Players[I].Booleans[II - 1];
except
end;
end;
{************************************************* ******************************
procedure InitForm;
By: IceFire908.
Description: Initializes the form.
************************************************** *****************************}
procedure InitForm;
var
FormInfo: TStringArray;
I, II: Byte;
begin
LoadPlayersFromFile;
FormInfo := ['go to the previous player', '<<', 'create a new player', 'Create Player', 'delete a player', 'Delete Player', 'go to the next player', '>>', 'start Rune Crafter ReBorn', 'Start RCrB', 'player is going to be used', '68', '214', 'you are using a small pouch', '336', '205', 'you are using a medium pouch', '412', '205', 'you are using a large pouch', '336', '225', 'you are using a gaint pouch', '412', '225', 'rune to craft at a location', 'skill to chose in the genie random event', '[Air] (FEB)', '[Mind] (FWB)', '[Water] (DB)', '[Earth] (VEB)', '[Fire] (AKB)', '[Body] (EB)', 'Agility', 'Attack', 'Construction', 'Cooking', 'Crafting', 'Defence',
'Farming', 'Firemaking', 'Fishing', 'Fletching', 'Herblore', 'Hitpoints', 'Hunting', 'Magic', 'Mining', 'Prayer', 'Ranged', 'Runecrafting', 'Slayer', 'Smithing', 'Strength', 'Thieving', 'Woodcutting', 'Current player # being viewed', '14', '51', 'Player # 0.', 'Check if player is going to be used', '84', '216', 'Player Active.', 'Type in your username here', '13', '90', 'Username:', 'Type in your password here', '216', '90', 'Password:', 'Type in the 2nd, 3rd, and 4th letters of your username here', '15', '120', 'Nickname:', 'Type in your bank pin here', '223', '120', 'Bank Pin:', 'Type in the amount of loads to do per a round here',
'38', '150', 'Loads:', 'Type in the amount of essence to craft', '217', '150', 'Essences:', 'Select a rune to craft at a location', '19', '180', 'Runecraft:', 'Select a skill to chose in the genie random event', '216', '180', 'Lamp Skill:', 'Check if you are using a small pouch', '352', '207', 'S Pouch.', 'Check if you are using a medium pouch', '428', '207', 'M Pouch.', 'Check if you are using a large pouch', '353', '227', 'L Pouch.', 'Check if you are using a gaint pouch', '428', '227', 'G Pouch.', '83', '88', '283', '88', '83', '118', '283', '118', '83', '148', '283', '148'];
Form := CreateForm;
with Form do
begin
Caption := 'Rune Crafter ReBorn v' + VersionNumber + ' by IceFire908. Powered by SRL.';
SetBounds(162, 102, 497, 268);
BorderStyle := BSToolWindow;
OnPaint := @LoadBackground;
OnCloseQuery := @FormClosed;
ShowHint := True;
end;
for I := 0 to 4 do
begin
Buttons[I] := TButton.Create(Form);
with Buttons[I] do
begin
Parent := Form;
Hint := 'Click to ' + FormInfo[(2 * I)] + '.';
SetBounds((69 + (88 * I)), 61, 85, 19);
if (I = 4) then
SetBounds(176, 208, 136, 29);
Caption := FormInfo[(1 + (2 * I))];
OnClick := @ButtonClick;
end;
end;
for I := 0 to 4 do
begin
CheckBoxes[I] := TCheckBox.Create(Form);
with CheckBoxes[I] do
begin
Parent := Form;
Hint := 'Check if ' + FormInfo[(10 + (3 * I))] + '.';
SetBounds(StrToInt(FormInfo[(11 + (3 * I))]), StrToInt(FormInfo[(12 + (3 * I))]), 17, 17);
end;
end;
for I := 0 to 1 do
begin
ComboBoxes[I] := TComboBox.Create(Form);
with ComboBoxes[I] do
begin
Parent := Form;
Hint := 'Select a ' + FormInfo[25 + I] + '.';
SetBounds((83 + (200 * I)), 178, 121, 21);
OnKeyPress := @OnKeyPress;
for II := 0 to (5 + (17 * I)) do
Items.Add(FormInfo[(27 + (6 * I) + II)]);
end;
end;
for I := 0 to 13 do
begin
Labels[I] := TLabel.Create(Form);
with Labels[I] do
begin
Parent := Form;
Font.Color := CLWhite;
Hint := FormInfo[(56 + (4 * I))] + '.';
SetBounds(StrToInt(FormInfo[(57 + (4 * I))]), StrToInt(FormInfo[(58 + (4 * I))]), 16, 66);
Font.Height := -13;
case I of
0, 1, 10, 11, 12, 13: Font.Height := -11;
end;
Caption := FormInfo[(59 + (4 * I))];
end;
end;
for I := 0 to 5 do
begin
Edits[I] := TEdit.Create(Form);
with Edits[I] do
begin
Parent := Form;
Hint := FormInfo[(64 + (4 * I))] + '.';
SetBounds(StrToInt(FormInfo[(112 + (2 * I))]), StrToInt(FormInfo[(113 + (2 * I))]), 121, 21);
case I of
1, 3: PasswordChar := '*';
end;
end;
end;
DeclareFormFromPlayers(0);
end;
Just some spoilers from RCrB v2.00 ;)
Omg, Ice-fire you always take any oppertunity to advertise it :p. Also how far are you done with it?
Shuttleu
02-08-2009, 02:53 PM
Very nice now if only you knew how to reduce all that code by about 300% using with do for do and arrays
{************************************************* ******************************
Form variables
************************************************** *****************************}
var
ComboBoxes: array[0..1] of TComboBox;
CheckBoxes: array[0..4] of TCheckBox;
Buttons: array[0..4] of TButton;
Labels: array[0..13] of TLabel;
Edits: array[0..5] of TEdit;
BackgroundPicture: LongInt;
CharsFileString: string;
StartScript: Boolean;
Form: TForm;
{************************************************* ******************************
procedure DeclareFormFromPlayers(I: LongInt);
By: IceFire908.
Description: Declares the settings from the SRL player array into the form.
************************************************** *****************************}
procedure DeclareFormFromPlayers(I: LongInt);
var
II: Byte;
begin
try
if (Players[I].Name <> '') then
Edits[0].Text := Players[I].Name
else
Edits[0].Text := 'New Username';
if (Players[I].Pass <> '') then
Edits[1].Text := Players[I].Pass
else
Edits[1].Text := 'New Password';
if (Players[I].Nick <> '') then
Edits[2].Text := Players[I].Nick
else
Edits[2].Text := 'New Nickname';
if (Players[I].Skill <> '') then
ComboBoxes[1].Text := Players[I].Skill
else
ComboBoxes[1].Text := 'Agility';
CheckBoxes[0].Checked := Players[I].Active;
if (Players[I].Strings[0] <> '') then
Edits[3].Text := Players[I].Strings[0]
else
Edits[3].Text := '0000';
if (Players[I].Strings[1] <> '') then
ComboBoxes[0].Text := Players[I].Strings[1]
else
ComboBoxes[0].Text := '[Air] (FEB)';
Edits[4].Text := IntToStr(Players[I].Integers[0]);
Edits[5].Text := IntToStr(Players[I].Integers[1]);
for II := 1 to 4 do
CheckBoxes[II].Checked := Players[I].Booleans[II - 1];
except
end;
end;
{************************************************* ******************************
procedure InitForm;
By: IceFire908.
Description: Initializes the form.
************************************************** *****************************}
procedure InitForm;
var
FormInfo: TStringArray;
I, II: Byte;
begin
LoadPlayersFromFile;
FormInfo := ['go to the previous player', '<<', 'create a new player', 'Create Player', 'delete a player', 'Delete Player', 'go to the next player', '>>', 'start Rune Crafter ReBorn', 'Start RCrB', 'player is going to be used', '68', '214', 'you are using a small pouch', '336', '205', 'you are using a medium pouch', '412', '205', 'you are using a large pouch', '336', '225', 'you are using a gaint pouch', '412', '225', 'rune to craft at a location', 'skill to chose in the genie random event', '[Air] (FEB)', '[Mind] (FWB)', '[Water] (DB)', '[Earth] (VEB)', '[Fire] (AKB)', '[Body] (EB)', 'Agility', 'Attack', 'Construction', 'Cooking', 'Crafting', 'Defence',
'Farming', 'Firemaking', 'Fishing', 'Fletching', 'Herblore', 'Hitpoints', 'Hunting', 'Magic', 'Mining', 'Prayer', 'Ranged', 'Runecrafting', 'Slayer', 'Smithing', 'Strength', 'Thieving', 'Woodcutting', 'Current player # being viewed', '14', '51', 'Player # 0.', 'Check if player is going to be used', '84', '216', 'Player Active.', 'Type in your username here', '13', '90', 'Username:', 'Type in your password here', '216', '90', 'Password:', 'Type in the 2nd, 3rd, and 4th letters of your username here', '15', '120', 'Nickname:', 'Type in your bank pin here', '223', '120', 'Bank Pin:', 'Type in the amount of loads to do per a round here',
'38', '150', 'Loads:', 'Type in the amount of essence to craft', '217', '150', 'Essences:', 'Select a rune to craft at a location', '19', '180', 'Runecraft:', 'Select a skill to chose in the genie random event', '216', '180', 'Lamp Skill:', 'Check if you are using a small pouch', '352', '207', 'S Pouch.', 'Check if you are using a medium pouch', '428', '207', 'M Pouch.', 'Check if you are using a large pouch', '353', '227', 'L Pouch.', 'Check if you are using a gaint pouch', '428', '227', 'G Pouch.', '83', '88', '283', '88', '83', '118', '283', '118', '83', '148', '283', '148'];
Form := CreateForm;
with Form do
begin
Caption := 'Rune Crafter ReBorn v' + VersionNumber + ' by IceFire908. Powered by SRL.';
SetBounds(162, 102, 497, 268);
BorderStyle := BSToolWindow;
OnPaint := @LoadBackground;
OnCloseQuery := @FormClosed;
ShowHint := True;
end;
for I := 0 to 4 do
begin
Buttons[I] := TButton.Create(Form);
with Buttons[I] do
begin
Parent := Form;
Hint := 'Click to ' + FormInfo[(2 * I)] + '.';
SetBounds((69 + (88 * I)), 61, 85, 19);
if (I = 4) then
SetBounds(176, 208, 136, 29);
Caption := FormInfo[(1 + (2 * I))];
OnClick := @ButtonClick;
end;
end;
for I := 0 to 4 do
begin
CheckBoxes[I] := TCheckBox.Create(Form);
with CheckBoxes[I] do
begin
Parent := Form;
Hint := 'Check if ' + FormInfo[(10 + (3 * I))] + '.';
SetBounds(StrToInt(FormInfo[(11 + (3 * I))]), StrToInt(FormInfo[(12 + (3 * I))]), 17, 17);
end;
end;
for I := 0 to 1 do
begin
ComboBoxes[I] := TComboBox.Create(Form);
with ComboBoxes[I] do
begin
Parent := Form;
Hint := 'Select a ' + FormInfo[25 + I] + '.';
SetBounds((83 + (200 * I)), 178, 121, 21);
OnKeyPress := @OnKeyPress;
for II := 0 to (5 + (17 * I)) do
Items.Add(FormInfo[(27 + (6 * I) + II)]);
end;
end;
for I := 0 to 13 do
begin
Labels[I] := TLabel.Create(Form);
with Labels[I] do
begin
Parent := Form;
Font.Color := CLWhite;
Hint := FormInfo[(56 + (4 * I))] + '.';
SetBounds(StrToInt(FormInfo[(57 + (4 * I))]), StrToInt(FormInfo[(58 + (4 * I))]), 16, 66);
Font.Height := -13;
case I of
0, 1, 10, 11, 12, 13: Font.Height := -11;
end;
Caption := FormInfo[(59 + (4 * I))];
end;
end;
for I := 0 to 5 do
begin
Edits[I] := TEdit.Create(Form);
with Edits[I] do
begin
Parent := Form;
Hint := FormInfo[(64 + (4 * I))] + '.';
SetBounds(StrToInt(FormInfo[(112 + (2 * I))]), StrToInt(FormInfo[(113 + (2 * I))]), 121, 21);
case I of
1, 3: PasswordChar := '*';
end;
end;
end;
DeclareFormFromPlayers(0);
end;
Just some spoilers from RCrB v2.00 ;)
RCrB?
~shut
Wanted
02-09-2009, 04:19 AM
Omg, Ice-fire you always take any oppertunity to advertise it :p. Also how far are you done with it?
What haha I'm not gonna discuss that here I'm not trying to advertise it I'm trying to show you people the advantages of reducing the code and showing an example
for I := 0 to 4 do
begin
CheckBoxes[i] := TCheckBox.Create(Form);
with CheckBoxes[i] do
begin
Parent := Form;
Hint := 'Check if ' + FormInfo[(10 + (3 * I))] + '.';
SetBounds(StrToInt(FormInfo[(11 + (3 * I))]), StrToInt(FormInfo[(12 + (3 * I))]), 17, 17);
end;
end;
Now tell me I didn't just open up a whole new world of possibilities for you? That would of normally taken forever to compile and probably like 150 lines, not to mention typing all that repetitive form code junk... cool thing is you can do this sort of thing with coding for anything not just forms... like color functions, splines, DDTMs ect. ect..
var
FormInfo: TStringArray;
I, II: Byte;
begin
LoadPlayersFromFile;
FormInfo := ['go to the previous player', '<<', 'create a new player', 'Create Player', 'delete a player', 'Delete Player', 'go to the next player', '>>', 'start Rune Crafter ReBorn', 'Start RCrB', 'player is going to be used', '68', '214', 'you are using a small pouch', '336', '205', 'you are using a medium pouch', '412', '205', 'you are using a large pouch', '336', '225', 'you are using a gaint pouch', '412', '225', 'rune to craft at a location', 'skill to chose in the genie random event', '[Air] (FEB)', '[Mind] (FWB)', '[Water] (DB)', '[Earth] (VEB)', '[Fire] (AKB)', '[Body] (EB)', 'Agility', 'Attack', 'Construction', 'Cooking', 'Crafting', 'Defence',
'Farming', 'Firemaking', 'Fishing', 'Fletching', 'Herblore', 'Hitpoints', 'Hunting', 'Magic', 'Mining', 'Prayer', 'Ranged', 'Runecrafting', 'Slayer', 'Smithing', 'Strength', 'Thieving', 'Woodcutting', 'Current player # being viewed', '14', '51', 'Player # 0.', 'Check if player is going to be used', '84', '216', 'Player Active.', 'Type in your username here', '13', '90', 'Username:', 'Type in your password here', '216', '90', 'Password:', 'Type in the 2nd, 3rd, and 4th letters of your username here', '15', '120', 'Nickname:', 'Type in your bank pin here', '223', '120', 'Bank Pin:', 'Type in the amount of loads to do per a round here',
'38', '150', 'Loads:', 'Type in the amount of essence to craft', '217', '150', 'Essences:', 'Select a rune to craft at a location', '19', '180', 'Runecraft:', 'Select a skill to chose in the genie random event', '216', '180', 'Lamp Skill:', 'Check if you are using a small pouch', '352', '207', 'S Pouch.', 'Check if you are using a medium pouch', '428', '207', 'M Pouch.', 'Check if you are using a large pouch', '353', '227', 'L Pouch.', 'Check if you are using a gaint pouch', '428', '227', 'G Pouch.', '83', '88', '283', '88', '83', '118', '283', '118', '83', '148', '283', '148'];
Form := CreateForm;
with Form do
begin
Caption := 'Rune Crafter ReBorn v' + VersionNumber + ' by IceFire908. Powered by SRL.';
SetBounds(162, 102, 497, 268);
BorderStyle := BSToolWindow;
OnPaint := @LoadBackground;
OnCloseQuery := @FormClosed;
ShowHint := True;
end;
for I := 0 to 4 do
begin
Buttons[I] := TButton.Create(Form);
with Buttons[I] do
begin
Parent := Form;
Hint := 'Click to ' + FormInfo[(2 * I)] + '.';
SetBounds((69 + (88 * I)), 61, 85, 19);
if (I = 4) then
SetBounds(176, 208, 136, 29);
Caption := FormInfo[(1 + (2 * I))];
OnClick := @ButtonClick;
end;
end;
for I := 0 to 4 do
begin
CheckBoxes[I] := TCheckBox.Create(Form);
with CheckBoxes[I] do
begin
Parent := Form;
Hint := 'Check if ' + FormInfo[(10 + (3 * I))] + '.';
SetBounds(StrToInt(FormInfo[(11 + (3 * I))]), StrToInt(FormInfo[(12 + (3 * I))]), 17, 17);
end;
end;
for I := 0 to 1 do
begin
ComboBoxes[I] := TComboBox.Create(Form);
with ComboBoxes[I] do
begin
Parent := Form;
Hint := 'Select a ' + FormInfo[25 + I] + '.';
SetBounds((83 + (200 * I)), 178, 121, 21);
OnKeyPress := @OnKeyPress;
for II := 0 to (5 + (17 * I)) do
Items.Add(FormInfo[(27 + (6 * I) + II)]);
end;
end;
for I := 0 to 13 do
begin
Labels[I] := TLabel.Create(Form);
with Labels[I] do
begin
Parent := Form;
Font.Color := CLWhite;
Hint := FormInfo[(56 + (4 * I))] + '.';
SetBounds(StrToInt(FormInfo[(57 + (4 * I))]), StrToInt(FormInfo[(58 + (4 * I))]), 16, 66);
Font.Height := -13;
case I of
0, 1, 10, 11, 12, 13: Font.Height := -11;
end;
Caption := FormInfo[(59 + (4 * I))];
end;
end;
for I := 0 to 5 do
begin
Edits[I] := TEdit.Create(Form);
with Edits[I] do
begin
Parent := Form;
Hint := FormInfo[(64 + (4 * I))] + '.';
SetBounds(StrToInt(FormInfo[(112 + (2 * I))]), StrToInt(FormInfo[(113 + (2 * I))]), 121, 21);
case I of
1, 3: PasswordChar := '*';
end;
end;
end;
DeclareFormFromPlayers(0);
end;
RcrB = Rune Crafter ReBorn :)
faster789
02-13-2009, 08:19 PM
Awesome Tut! :)
Btw, is your ultimate PCER actually coming back?! :D
Laur€ns
02-25-2009, 12:44 PM
Wow.
superbatman
03-11-2009, 05:03 AM
Great Tut, But When I add the BackGround, it makes the labels blank, i think it might be because the images are .png instead of .bmp
MasterKill
03-11-2009, 06:23 AM
Great Tut, But When I add the BackGround, it makes the labels blank, i think it might be because the images are .png instead of .bmp
You have to call your TImage, before all other form components like labels. Else you will create a TImage overlaying the labels :)
FrmDesign := TForm;
Image1 := TImage.Create(FrmDesign);
// all other stuff
GL :)
Dark Arcana
03-11-2009, 12:26 PM
Very nice tutorial I learnt a lot. Goodjob ;)
XRaye
03-27-2009, 02:35 AM
This is AWESOME. I'm at TEdit right now and so far this tutorial is sweet. I've always wondered how people make their forms look so awesome (Like you) and it's way easier than I thought so far.
Awkwardsaw
03-27-2009, 02:48 AM
when are you going to finish? so far its been helping me a LOT, and its kind of disapointing that its not finished =D so far, i made my form and every thing, but im not for sure on how to make the usename and such actually do something (like saving what you type into the box thing, and using it in the script itself)
iv been looking in other tuts, and so far i cant find any scripts to use as an example
thanks =D
XRaye
03-27-2009, 02:51 AM
Arrays can be used for TEdit and the other things too right?
EDIT:
Line 92: [Error] (92:11): Unknown identifier 'PASSWORDCHAR' in script
Line 92 is: ComboBox1.PasswordChar := '*';
Are you sure you can use PasswordChar in that? The char limit works fine, and I've checked over this thing to make sure it's right, but I can't figure out anything wrong.
MasterKill
03-27-2009, 06:42 AM
FEditB[1].PasswordChar := '*';
That comes right out of one of my scripts. It should work. At what scar version are you?
XRaye
03-27-2009, 09:38 PM
SCAR 3.15b, but it doesn't matter that much, I wouldn't want to use it.
And I'm getting the error "Identifier Expected" on the line of the SafeInitForm procedure. How to fix?
EDIT: I was missing a end;...
Claymore
06-20-2009, 01:26 PM
um about tform, how can we make the window un-resizable, un-minimizable, un-maxamazible if that makes any sense.
MasterKill
06-20-2009, 01:47 PM
You can remove the "outline" of the form with this code:
frmDesign.BorderStyle := bsNone;
That will remove the minisize, hide, and close button. Don't forget to make a new close button yourself though :p
Claymore
06-20-2009, 01:54 PM
roflcopter, when i made my form, i was wondering why it wudnt close ever sine i popped in the code. ^^
k ill look into ur guide more ^^ hope u finished this. because my mining script wont be realeased until i get this awesome form finished.
MasterKill
06-20-2009, 04:52 PM
roflcopter, when i made my form, i was wondering why it wudnt close ever sine i popped in the code. ^^
k ill look into ur guide more ^^ hope u finished this. because my mining script wont be realeased until i get this awesome form finished.
3 more weeks of school for me, after that I'll finnish it. I've had some real positive comments on this tutorial already, so it would be a waste if I didn't finnish it.
:)
Claymore
06-21-2009, 04:00 AM
and i finished school (well the school gave us an early holiday, but we have to use the first 2 weeks to study for the exams on July which is a QQ).
anyways i finished reading your guide, decided to dive onto developing my form. than i decided, hey why not make it neater like MK did.
And now i made my form, neat and still "working" (you know, still doesnt have buttons and stuff ready..) but hey! atleast it pops up with nice text boxes, a kick ass background and a kick ass banner ^^ ill upload it to you so you can see what you've taught me.
rest assured though, you taught me well. and these 4 boobless hours of my life was no waste when reading your guide ^^ it was worth it.
EDIT
This time i didnt forget to add the close function thingy! ^^
So please comment on my Form, would really love to know what you think of my 0wesomness 1337ness :p
MasterKill
06-21-2009, 08:19 PM
and i finished school (well the school gave us an early holiday, but we have to use the first 2 weeks to study for the exams on July which is a QQ).
anyways i finished reading your guide, decided to dive onto developing my form. than i decided, hey why not make it neater like MK did.
And now i made my form, neat and still "working" (you know, still doesnt have buttons and stuff ready..) but hey! atleast it pops up with nice text boxes, a kick ass background and a kick ass banner ^^ ill upload it to you so you can see what you've taught me.
rest assured though, you taught me well. and these 4 boobless hours of my life was no waste when reading your guide ^^ it was worth it.
EDIT
This time i didnt forget to add the close function thingy! ^^
So please comment on my Form, would really love to know what you think of my 0wesomness 1337ness :p
Wow that really looks nice! Good job! :)
Deathsyntax, you can make your form move. PM me if you want to know how :)
Claymore
06-22-2009, 04:18 AM
so for load fp, will it basically do this
procedure loadfp(c: integer; saveCurrentInfo: boolean);
begin
inc(howManyPlayers);
players[c].name := edits[0].text;
//etc...
end;
i dont really understand what loadfp means. shouldnt it be called savefp because you putting the .text on the player info. not really loading it at all :/
EDIT:
so i did this
try
howmanyplayers := howmanyplayers+1;
numberofplayers(howmanyplayers);
players[c].name := edits[0].text;
//etc..
except
showmessage('roflcopter away!!!!!');
exit;
end;
c:=howmanyplayers;
so now how do i make it reveal to the player list?
MasterKill
06-22-2009, 01:04 PM
Death, please wait a while, cause LoadFP Isn't that easy :p When I have a few hours free I'll work on this, buy for now I really should learn for my lasts tests of the first year IT ;)
Umm.. I need to know if I could like.. Have a map of RS that you could move around, then when you mouse over a certain part, it will highlight it then if you click it, that will be the place you want to use for the script? And also it will have a list of multiple places so when you mouse over the text of the multiple places, it will highlight the patches I want it to and show you where they are? :p (Zoom out and show) thanks, MK! :D
MasterKill
07-03-2009, 01:42 PM
That would be very hard to make :p What you can do and wish is a lot easyer:
Make a combobox with all the placed you have, when the users clicks on falador for example the TImage will change to a picture of falador. something like this:
If OnClickComboBox({bla}) Then
Begin
Case ComboBox[?].IndexItem Of
0: // load image falador
1: // load image varrock
// ect
End;
End;
Oh okay. Would that lag at all? (Like would there be any way to make it load first and then when you choose that box it just immediately changes the picture?)
MasterKill
07-06-2009, 09:07 PM
My eyes are bleeding, I see pixels flying around my room, but I did it, I've completed the "Create a player setup form" tutorial.
ENJOY!
~ Rick.
Claymore
07-07-2009, 09:33 AM
Zomg@!!!!!!! Tyssszzz
Awkwardsaw
07-07-2009, 09:35 AM
ZOMG i love you. :D
+ rep fo sho
MasterKill
07-09-2009, 04:44 AM
I really hope the tutorials is helping, and I would love to see screenshots of results, wish I'll post in the first post :)
King of the Nites
07-09-2009, 09:33 AM
When I finish, I will definitely show you the results!
Rep ++ and this tutorial explains everything, great job!!
~KotN
Coh3n
07-22-2009, 04:06 AM
Awesome guide, it's really working for me so far. :D I do have one question.
Can you not take away the border from TButtons? I have:
Buttons[i].BorderStyle := NSNone
I always get "Unknown identifier BORDERSTYLE in script...". I'm going for the medieval RS look for this form, and I think the current TButton borders look too "futuristic" if you know what I mean. If you have any ideas, please let me know. :)
Thanks.
MasterKill
07-22-2009, 05:47 AM
Awesome guide, it's really working for me so far. :D I do have one question.
Can you not take away the border from TButtons? I have:
Buttons[i].BorderStyle := NSNone
I always get "Unknown identifier BORDERSTYLE in script...". I'm going for the medieval RS look for this form, and I think the current TButton borders look too "futuristic" if you know what I mean. If you have any ideas, please let me know. :)
Thanks.
you could make your own buttons using a TImage, and just add a .OnClick to it ;) that way you could have your own custom buttons :)
Good luck!
Coh3n
07-22-2009, 05:48 AM
you could make your own buttons using a TImage, and just add a .OnClick to it ;) that way you could have your own custom buttons :)
Good luck!
Ah good call. :) Thanks.
EDIT: I'll post a screenshot when I'm done the form. :)
Cazax
07-22-2009, 05:50 AM
Ah good call. :) Thanks.
If you have any doubt you can look at this (http://www.villavu.com/forum/showthread.php?t=47427) :)
@MK: Nice tutorial, well explained.
Coh3n
07-22-2009, 08:10 AM
If you have any doubt you can look at this (http://www.villavu.com/forum/showthread.php?t=47427) :)
Looks nice, thanks. :)
@ MK: I like the idea of using TImages to make my own custom buttons, but is there a way that when I hover over that button with my mouse, the image changes to indicate I'm hovered over the button. Just like the default buttons kind of "glow" when the mouse is hovered over them.
Basically I want the image to "indent" into the screen when I hover over it. If you don't know what I mean, check out the "X" when closing a window in RS.
While I'm asking questions, I'll also ask if I can have a caption come up when I hover over the button that gives a small explaining like "Exits the form" and things along those lines.
If this is possible that would be great. :)
Thanks.
Cazax
07-22-2009, 08:15 AM
Use this events:
OnMouseMove: When the mouse moves inside the Image it will be convoked.
OnMouseDown: When the mouse is down inside the Image it will be convoked.
OnMouseUp: When the mouse is up inside the Image it will be convoked.
Coh3n
07-22-2009, 08:48 AM
Use this events:
OnMouseMove: When the mouse moves inside the Image it will be convoked.
OnMouseDown: When the mouse is down inside the Image it will be convoked.
OnMouseUp: When the mouse is up inside the Image it will be convoked.
Talk on MSN? Check PMs. :)
I don't know what you mean when you say "inside" the image. Do you mean the mouse is over top the image? Saying it's inside sounds kind of weird to me. Lol.
Cazax
07-22-2009, 08:54 AM
Over the Image, if that makes it clear.
Coh3n
07-22-2009, 09:26 AM
Over the Image, if that makes it clear.
It does, thanks, except I have no idea how I would use those. It says OnMouseMove is a TMouseMoveEvent and I have no idea what that is. :confused:
Is there like a database or something that has descriptions of all these little functions?
It does, thanks, except I have no idea how I would use those. It says OnMouseMove is a TMouseMoveEvent and I have no idea what that is. :confused:
Is there like a database or something that has descriptions of all these little functions?
Check Daniel's quality (:D) Tutorials :)
noidea
07-26-2009, 02:07 AM
http://img24.imageshack.us/img24/69/sfycimageshcaks.jpg
MasterKill: Adding and delting players, ect :D Tabs (Thx to you)
Thanks so much. I made this about a week ago on like 3 car trips. tysm :)
http://img24.imageshack.us/img24/69/sfycimageshcaks.jpg
MasterKill: Adding and delting players, ect :D Tabs (Thx to you)
Thanks so much. I made this about a week ago on like 3 car trips. tysm :)
Pretty nice GUI, what OS are you on?
MasterKill
07-30-2009, 01:23 AM
http://img24.imageshack.us/img24/69/sfycimageshcaks.jpg
MasterKill: Adding and delting players, ect :D Tabs (Thx to you)
Thanks so much. I made this about a week ago on like 3 car trips. tysm :)
looks pretty nice! You did most by following my tutorial? Good job :) Wanna be in my first post "wall of fame" ?
Nau: probably windows vista with another border style :o
noidea
07-30-2009, 01:25 AM
looks pretty nice! You did most by following my tutorial? Good job :)
Nau: probably windows vista with another border style :o
The tabs and the pic were thx to you <3
and the wall of fame would be awsome <3
MasterKill
07-30-2009, 05:10 PM
The tabs and the pic were thx to you <3
and the wall of fame would be awsome <3
I didn't learn tabs though? :p Or you mean the player adding stuff :o anyway, added to the first page ;) The form looks nice :)
All learned from this tutorial:
http://img300.imageshack.us/img300/8352/formfinished.png
Thanks mucho... never really learned this stuff until now. Easier than I thought it would be. xD Maybe finish the player array stuff... I might try my hand at it on a 3 hour drive home I got tomorrow though.
MasterKill
08-03-2009, 05:06 AM
All learned from this tutorial:
http://img300.imageshack.us/img300/8352/formfinished.png
Thanks mucho... never really learned this stuff until now. Easier than I thought it would be. xD Maybe finish the player array stuff... I might try my hand at it on a 3 hour drive home I got tomorrow though.
Added to wall of fame! All I need to finnish is the saving and loading ;) I'll add that when I'm back from France ;)
Richard
08-04-2009, 06:18 AM
Me wants wall of fame :)
http://i25.tinypic.com/5x7voh.jpg
Been working on that for quite a while, still a flaw with the RadioButton, should sort it soon.
candythief
08-04-2009, 12:12 PM
i did the sig for mormonmans form :)
i did the sig for mormonmans form :)
ya, with my freaking help D=
I want hall of fame as well!
http://i43.tinypic.com/wjgllf.jpg
:)
You only get it if you learned the stuff from this tut. BTW, my second form is almost done... just need to make background and banner.
Edit: Background done, border taken from runescape.com xD
http://img442.imageshack.us/img442/6932/formdone.png
My next form is going to have custom buttons.
You only get it if you learned the stuff from this tut. BTW, my second form is almost done... just need to make background and banner.
Edit: Background done, border taken from runescape.com xD
http://img442.imageshack.us/img442/6932/formdone.png
My next form is going to have custom buttons.
I learned it from this tut, well the TImage part :).
Can I haz hall of fame?
MasterKill
08-04-2009, 06:52 PM
@Nua: nice, adding :)
@Richard: very added :) good job
@mormonman: also nice, but I will only add one entry to the wall of fame for each person :) I will replace your second one when it's done?
@all: I love to see this tutorial is helping! Thanks for posting results!
Claymore
08-06-2009, 12:59 AM
Hey MK, back from playing DotA tournaments. I dithced RS since my neighber was holding up a tourney i was all like O_o must are practize for PIEZZZ!!!!
Anyways, im still workin on mine. Since you didnt release the functions, i had to make my own functions. Now that you DID RELEASE your functions, i got to redo everything (well functions only) and im done ^^ Hallz of famez for meh pl0xxx
MasterKill
08-06-2009, 02:22 AM
Hey MK, back from playing DotA tournaments. I dithced RS since my neighber was holding up a tourney i was all like O_o must are practize for PIEZZZ!!!!
Anyways, im still workin on mine. Since you didnt release the functions, i had to make my own functions. Now that you DID RELEASE your functions, i got to redo everything (well functions only) and im done ^^ Hallz of famez for meh pl0xxx
picture plox :p
meh, the banner doesn't match the background but who cares :P
http://img269.imageshack.us/img269/6932/formdone.png
x[Warrior]x3500
08-17-2009, 04:11 AM
hey, great tut. but i am having problems making my players active. it keeps saying that they are not active and wont log them into the game.
here is my current form. use to drop down menu above the player box to change whether the player is active or not.
also, my images/background wont show up because i didnt provide the files.
thx for the help and tut.
MasterKill
08-17-2009, 06:30 AM
x3500;616762']hey, great tut. but i am having problems making my players active. it keeps saying that they are not active and wont log them into the game.
here is my current form. use to drop down menu above the player box to change whether the player is active or not.
also, my images/background wont show up because i didnt provide the files.
thx for the help and tut.
x[Warrior]x3500, I have made a mistake, thank you very much for posting it.
at the end, when you press start, the script shouldn't save fp[i].active in .booleans[0], but in .Active
Try
Players[I].Active := StrToBool(FP[I].Active);
Except
LoadFP(I, False);
ShowMessage('Oops, ' + FP[I].Name + ' has a wrong "active" amoult!' +
' choose an option from the drop down box!');
Exit;
End;
That will fix it all.
Once again, thanks for posting my mistake, and thanks for your nice comment on the rest <3
btw, I guess you helped some other people with this to now ;)
Amazing tutorial. Thanks :)
When are you going to update the saving and loading players part?
Or can you point me in the right direction. I can't seem to get saving and loading to work.
fifa499
09-02-2009, 02:40 PM
i read the entire thin but i don't understand do i do both part's? how does it go together i sooooo suck at this =[ .
x[Warrior]x3500
09-03-2009, 02:20 AM
i read the entire thin but i don't understand do i do both part's? how does it go together i sooooo suck at this =[ .
the top part of this tut are just listing components of a form and what they can do. to actually start making the form, you need to go to the section after the components (use table of contents at top of the tut).
Smarter Child
09-03-2009, 06:52 AM
i read the entire thin but i don't understand do i do both part's? how does it go together i sooooo suck at this =[ .
Forget it, forms aren't needed, and i don't think your advanced enough. It might just make you frustrated.:sasmokin:
uncfan1119
10-10-2009, 03:00 PM
http://i34.tinypic.com/141v6dl.png
This is just a start :) I plan to add country (dropdown) and make the day, month, and year a drop down. Also I will add multiplayer support, but lets not get to far ahead.
Great guide!
MasterKill
10-13-2009, 05:37 AM
http://i34.tinypic.com/141v6dl.png
This is just a start :) I plan to add country (dropdown) and make the day, month, and year a drop down. Also I will add multiplayer support, but lets not get to far ahead.
Great guide!
Good start, nice to see some one experimenting with forms again :) Thanks for your reply
crusader657
11-01-2009, 04:59 PM
Thanks! I am really trying to learn how to script and this has been a big help!
IwriteCode
11-23-2009, 03:17 PM
WOW, i think making a GUI for my scripts would be awesome. Will read all that thanks!
tom99
12-07-2009, 11:02 AM
Nice tutorial
Could you create an example of an code witch ask for input for username, password and a start button script and a writein('Bot has runned for ((+instr) command that display each 10 minutes, how long it has been going, i got problems with understanding it all.
Can you reveal the source on the first form, it is very well done, i woud like to learn to make forms witch is similiar to it.
Where do i put PlayerList := TListBox.Create(FrmDesign);
PlayerList.Parent := FrmDesign;
PlayerList.Top := 120;
PlayerList.Left := 10;
PlayerList.Width := 100;
PlayerList.Height := 170;
PlayerList.OnClick := @ItemClicked;
and i also get Unknown indentifier Frmdesign, do i need to create an new prodecure at playerlist, because if i put it with the variable i get multiplie indentifer, what do i do at this point?
tom99
12-17-2009, 09:37 AM
I got a form witch i like, and im wondering of why my script stops after entered chosen username/pass, thats just the beginning of the script, the form code is correct but it wont continue with the script help me with this plz. :duh:
i use the form code seperatet from the script i want to use with include if that matters.
*Sigh* Tom could you please edit your posts instead of posting one after the other?
bbri06
12-24-2009, 11:06 PM
Great form tutorial +rep.
marpis
12-25-2009, 05:33 PM
When I get my awesome Kharid Chef form ready (it has tabs!) it will totally pwn this hall of fame! :) Thanks for a great tut! I have learned everything except tabs here.
E: Haha! My catcup has a christmas hat!
MasterKill
12-28-2009, 09:19 PM
Thanks guys. If you post your form I'll place it in the wall of fame marpis ;)
Coh3n
01-12-2010, 04:40 AM
Just wondering how I would add a dragging feature to my form using the properties, etc. I've tried messing around with them (BeginDrag, EndDrag, etc.), but I haven't been doing it right. I don't have much form knowledge, so don't use super-advanced terms. :p
All I want it to do is drag around the screen when I click and drag the mouse over the background image.
Hopefully someone can help me out.
Thanks,
Coh3n
Helped a lot. I was kinda lost on where to start for my player form. You might consider updating it to be Simba Compatible. Rep+
~BraK
KingKong
12-25-2010, 02:53 AM
Rep +, Awesome tut, I found this by accident when i just wanted to learn about forms
Death12652
12-26-2010, 06:10 PM
I keep getting this in the Image part.
[Error] (123:1): Unknown identifier 'copycanvas' at line 122
Coh3n
12-27-2010, 10:28 PM
I keep getting this in the Image part.
[Error] (123:1): Unknown identifier 'copycanvas' at line 122
This tutorial was written for SCAR. CopyCanvas is DrawBitmap in Simba I believe.
wundertüte
07-25-2011, 06:05 PM
i want to ask if there is a way to see my form always ontop while my script is running ?
i made a script that auto send fire to the window when my attack button shows that attacking is possible
to prevent firing on other players i want to make a form always ontop with a green or red image to show if autofire is on or off at the moment
Smarter Child
07-26-2011, 10:14 PM
i want to ask if there is a way to see my form always ontop while my script is running ?
i made a script that auto send fire to the window when my attack button shows that attacking is possible
to prevent firing on other players i want to make a form always ontop with a green or red image to show if autofire is on or off at the moment
Not 100% sure what you are trying to do, but I don't think you need a form for this sort of thing. Rather, let the script bot for you entirely?
Brandon
07-27-2011, 01:14 AM
He's talking about on Smart GUI's..
And Im here to say yes its possible but only if I can figure out how to:
Make my script run even while my form is open..
The biggest problem is that my form has to do:
Form1.ModalResult:= mrOk;
When that happens, my form closes... So bs.. I don't want my form to close I want it to stay open but still have my script run.. if I can do that, I will show anyone how to have GUI's on Smart which I have just created myself..
That's why no forms have been use for proggies in real time before. :( When you open a form the script pauses to do the Form and only continues on the forms closing.
~BraK
TomTuff
07-27-2011, 05:48 AM
You could have a button enter the main loop of the script.
You could have a button enter the main loop of the script.
Pretty sure that is not really possible, but for more information check http://villavu.com/forum/showthread.php?t=39078 for Dan Cardin's tut.
~BraK
Brandon
07-27-2011, 07:01 AM
Tried what Tom suggested.. it works BUT.. My form freezes if I try to click it..
I can't believe this isn't possible.. really though.. we actually have to wait until a form closes inorder for the script to continue.. There is no override either :c
Not only that, while a form is open, simba is inaccessible.. U can't click anything until the form is closed.. waw..
It was explained to me one time that it only runs on one processing thread. I'm sure someone else can better explain the Simba/Smart and why we can't multithread. but yea it's been known that it wasn't possible for quite a while. Ask Wizzup? on IRC or something he know I'm sure.
~BraK
masterBB
07-27-2011, 07:49 AM
You could use a TTimer, but then you will have to adjust every piece of code to work with a 'fps'-like system.
You could use a TTimer, but then you will have to adjust every piece of code to work with a 'fps'-like system.
^ this is a valid suggestion but would still have v this problem
while a form is open, simba is inaccessible.. U can't click anything until the form is closed.. waw..
Just thought I'd point this out. Along with TTimer being a Pain. :)
~BraK
Coh3n
07-27-2011, 08:58 PM
It's because we don't have multithreading. It's either Simba doesn't support it, or PS doesn't. If PS doesn't, there isn't much we can do.
Brandon
07-27-2011, 09:41 PM
Ummm I figured that out.. instead of ShowModal you can do Show...
But what happens is that if u click simba, the form will now disappear instead.. Not sure why we use a language that is so restricted... Can't do anything..
Meh I have GUI's on smart working now.. fully working except I get access violation now.. and stuff :c
My sig has the thread with it.. I give up.. anyone want to continue it they can else its just going to die like Home said.
Ummm I figured that out.. instead of ShowModal you can do Show...
But what happens is that if u click simba, the form will now disappear instead.. Not sure why we use a language that is so restricted... Can't do anything..
Meh I have GUI's on smart working now.. fully working except I get access violation now.. and stuff :c
My sig has the thread with it.. I give up.. anyone want to continue it they can else its just going to die like Home said.
Dont Give Up...
Shatterhand
02-16-2012, 06:22 PM
Pretty good tutorial, thanks alot!
xdarkshadowx
01-02-2013, 07:51 AM
Not simba compatable :/
Sk1nyNerd
08-04-2013, 01:16 AM
anyone know how to save/load players into the form? :) took a break and need some help ha
Shatterhand
08-04-2013, 07:52 AM
anyone know how to save/load players into the form? :) took a break and need some help ha
You will need to store each profile in a text file. Check out my fighter script, LoadData and SaveData functions.
Sk1nyNerd
08-04-2013, 04:07 PM
You will need to store each profile in a text file. Check out my fighter script, LoadData and SaveData functions.
nice! thankyou
what is the #13 (http://villavu.com/forum/usertag.php?do=list&action=hash&hash=13) #10 when saving the data? (feel free to pm)
'UserName = ' + UserName + ';' #13 (http://villavu.com/forum/usertag.php?do=list&action=hash&hash=13) #10
tealc
08-04-2013, 07:32 PM
nice! thankyou
what is the #13 (http://villavu.com/forum/usertag.php?do=list&action=hash&hash=13) #10 when saving the data? (feel free to pm)
'UserName = ' + UserName + ';' #13 (http://villavu.com/forum/usertag.php?do=list&action=hash&hash=13) #10
it creates a new line similar to '/n' if your familiar with C.
mess with this in simba
writeln('line1' #13#10 'line2');
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.