Creating forms and applying them to scripts. By: Mad Cow What is a Form? A form is basically an easy way to set-up your scripts. It provides a user-friendly interface where you can type in all your information. Requirements Some basic SCAR knowledge required. Overview We will be making a Form that saves our Username and Password. You will learn how to create: Labels, Edit boxes and Buttons. Getting started What we will need to do is open the Form editor in SCAR. You can do this by going Tools -> Form Editor. Once that is open, 3 boxes should appear. Labels Now on the top box, click on the "A" then click anywhere on the Blank form(preferably towards the left). Now we must change the name. Eg. Now create another label for the password. Edit boxes Now that we have created the labels, we need some boxes for the user to add text in. Click on the box next to the Label one and make a click next to the Username and Password box. You may remove the caption. Eg. Start Button Now we got the Hard stuff out the way it's time to add a button so when you click, the Form will close. A couple of spaces to the right of the "Edit" button should be a box with the word "OK" in it. Click on that then click where you want your button to be. I"d personally put it the start button at the bottom, but it"s your choice. Eg. Resizing and changing the name Resize the window to whatever fits best. Now click on the icon that looks like this: Now click click anywhere on the for(Not on the buttons or labels) then change the Caption. Eg. Implementing the form into the script Save it by pressing the save icon then close the form editor. Now we go to: Tools -> Load DFM form Then click on the form that you just saved. You should get a bunch of lines. Add the files that it says to the variables. Eg. Code (Text): var frmDesign : TForm; Label1 : TLabel; Label2 : TLabel; Edit2 : TEdit; Edit1 : TEdit; Button1 : TButton; Now create a new procedure called initForm then paste all those lines above the var into it. Eg. Code (Text): program FormBegginerTutorial; var frmDesign : TForm; Label1 : TLabel; Label2 : TLabel; Edit2 : TEdit; Edit1 : TEdit; Button1 : TButton; procedure InitForm; begin frmDesign := CreateForm; frmDesign.Left := 250; frmDesign.Top := 114; frmDesign.Width := 263; frmDesign.Height := 180; frmDesign.Caption := 'User and Pass Saver'; frmDesign.Color := clBtnFace; frmDesign.Font.Color := clWindowText; frmDesign.Font.Height := -11; frmDesign.Font.Name := 'MS Sans Serif'; frmDesign.Font.Style := []; frmDesign.Visible := True; frmDesign.PixelsPerInch := 96; Label1 := TLabel.Create(frmDesign); Label1.Parent := frmDesign; Label1.Left := 32; Label1.Top := 40; Label1.Width := 51; Label1.Height := 13; Label1.Caption := 'Username:'; Label2 := TLabel.Create(frmDesign); Label2.Parent := frmDesign; Label2.Left := 33; Label2.Top := 65; Label2.Width := 49; Label2.Height := 13; Label2.Caption := 'Password:'; Edit2 := TEdit.Create(frmDesign); Edit2.Parent := frmDesign; Edit2.Left := 93; Edit2.Top := 37; Edit2.Width := 121; Edit2.Height := 21; Edit2.TabOrder := 8; Edit1 := TEdit.Create(frmDesign); Edit1.Parent := frmDesign; Edit1.Left := 93; Edit1.Top := 62; Edit1.Width := 121; Edit1.Height := 21; Edit1.TabOrder := 9; Button1 := TButton.Create(frmDesign); Button1.Parent := frmDesign; Button1.Left := 79; Button1.Top := 99; Button1.Width := 75; Button1.Height := 25; Button1.Caption := 'Start!'; Button1.TabOrder := 10; end; begin end. Now we will add three more procedures. Code (Text): 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; These procedures are just to make sure that the form will not freeze. Add these two lines to your main begin. Code (Text): begin SafeInitForm; SafeShowFormModal; end. Now we will need to remove the form visibility. Find the line that looks like this. Code (Text): frmDesign.Visible := True; And change it to this Code (Text): frmDesign.Visible := False; Now we are basically done. In the InitForm procedure, look for the the button lines. You should find something like this Code (Text): Button1 := TButton.Create(frmDesign); Button1.Parent := frmDesign; Button1.Left := 79; Button1.Top := 99; Button1.Width := 75; Button1.Height := 25; Button1.Caption := 'Start!'; Button1.TabOrder := 10; Change it to Code (Text): Button1 := TButton.Create(frmDesign); Button1.Parent := frmDesign; Button1.OnClick := @ButtonClick; Button1.Left := 79; Button1.Top := 99; Button1.Width := 75; Button1.Height := 25; Button1.Caption := 'Start!'; Button1.TabOrder := 10; This will call the procedure ButtonClick when clicked. Making the start button useful Lets create a new procedure above InitForm. Code (Text): procedure ButtonClick(sender: TObject); begin end; Now lets make the button close when we click it. Add the following lines of scar to your buttonclick procedure. Code (Text): WriteLn('You have clicked the button'); frmDesign.Caption:= frmDesign.Caption + '.'; frmDesign.ModalResult:= mrOk; You should now have something like this: Code (Text): program FormBegginerTutorial; var frmDesign : TForm; Label1 : TLabel; Label2 : TLabel; Edit2 : TEdit; Edit1 : TEdit; Button1 : TButton; procedure ButtonClick(sender: TObject); begin WriteLn('You have clicked the button'); frmDesign.Caption:= frmDesign.Caption + '.'; frmDesign.ModalResult:= mrOk; end; procedure InitForm; begin frmDesign := CreateForm; frmDesign.Left := 250; frmDesign.Top := 114; frmDesign.Width := 263; frmDesign.Height := 180; frmDesign.Caption := 'User and Pass Saver'; frmDesign.Color := clBtnFace; frmDesign.Font.Color := clWindowText; frmDesign.Font.Height := -11; frmDesign.Font.Name := 'MS Sans Serif'; frmDesign.Font.Style := []; frmDesign.Visible := False; frmDesign.PixelsPerInch := 96; Label1 := TLabel.Create(frmDesign); Label1.Parent := frmDesign; Label1.Left := 32; Label1.Top := 40; Label1.Width := 51; Label1.Height := 13; Label1.Caption := 'Username:'; Label2 := TLabel.Create(frmDesign); Label2.Parent := frmDesign; Label2.Left := 33; Label2.Top := 65; Label2.Width := 49; Label2.Height := 13; Label2.Caption := 'Password:'; Edit2 := TEdit.Create(frmDesign); Edit2.Parent := frmDesign; Edit2.Left := 93; Edit2.Top := 37; Edit2.Width := 121; Edit2.Height := 21; Edit2.TabOrder := 8; Edit1 := TEdit.Create(frmDesign); Edit1.Parent := frmDesign; Edit1.Left := 93; Edit1.Top := 62; Edit1.Width := 121; Edit1.Height := 21; Edit1.TabOrder := 9; Button1 := TButton.Create(frmDesign); Button1.OnClick := @ButtonClick; Button1.Parent := frmDesign; Button1.Left := 79; Button1.Top := 99; Button1.Width := 75; Button1.Height := 25; Button1.Caption := 'Start!'; Button1.TabOrder := 10; 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. Almost done! Now we will add 2 new variables called Username and Password and save them as strings. Code (Text): var Username, Password : String; Now create another procedure called SetupAll. We will now add the following lines of scar. Code (Text): procedure SetupAll; begin Username := Edit1.Text; Password := Edit2.Text; end; Now what this will do is save whatever is in the Edit boxes as Username and Password. Just to test that it works, in the main procedure add: Code (Text): WriteLn('Username = ' + Username); Writeln('Password = ' + Password); And now you should successfully have your Username and password you typed in. NOTE: To make your password appear as "*" when you type, add the following scar. Code (Text): Edit2 := TEdit.Create(frmDesign); Edit2.Parent := frmDesign; Edit2.Left := 93; Edit2.Top := 62; Edit2.Width := 121; Edit2.Height := 21; Edit2.TabOrder := 9; Change it to Code (Text): Edit2 := TEdit.Create(frmDesign); Edit2.Parent := frmDesign; Edit2.Left := 93; Edit2.Top := 62; Edit2.Width := 121; Edit2.Height := 21; Edit2.TabOrder := 9 Edit2.PasswordChar:= '*'; I finished with the following scar: Code (Text): program FormBegginerTutorial; var frmDesign : TForm; Label1 : TLabel; Label2 : TLabel; Edit2 : TEdit; Edit1 : TEdit; Button1 : TButton; Username, Password : String; procedure ButtonClick(sender: TObject); begin WriteLn('You have clicked the button'); frmDesign.Caption:= frmDesign.Caption + '.'; frmDesign.ModalResult:= mrOk; end; procedure InitForm; begin frmDesign := CreateForm; frmDesign.Left := 250; frmDesign.Top := 114; frmDesign.Width := 263; frmDesign.Height := 180; frmDesign.Caption := 'User and Pass Saver'; frmDesign.Color := clBtnFace; frmDesign.Font.Color := clWindowText; frmDesign.Font.Height := -11; frmDesign.Font.Name := 'MS Sans Serif'; frmDesign.Font.Style := []; frmDesign.Visible := False; frmDesign.PixelsPerInch := 96; Label1 := TLabel.Create(frmDesign); Label1.Parent := frmDesign; Label1.Left := 32; Label1.Top := 40; Label1.Width := 51; Label1.Height := 13; Label1.Caption := 'Username:'; Label2 := TLabel.Create(frmDesign); Label2.Parent := frmDesign; Label2.Left := 33; Label2.Top := 65; Label2.Width := 49; Label2.Height := 13; Label2.Caption := 'Password:'; Edit1 := TEdit.Create(frmDesign); Edit1.Parent := frmDesign; Edit1.Left := 93; Edit1.Top := 37; Edit1.Width := 121; Edit1.Height := 21; Edit1.TabOrder := 8; Edit2 := TEdit.Create(frmDesign); Edit2.Parent := frmDesign; Edit2.Left := 93; Edit2.Top := 62; Edit2.Width := 121; Edit2.Height := 21; Edit2.TabOrder := 9; Edit2.PasswordChar:= '*'; Button1 := TButton.Create(frmDesign); Button1.OnClick := @ButtonClick; Button1.Parent := frmDesign; Button1.Left := 79; Button1.Top := 99; Button1.Width := 75; Button1.Height := 25; Button1.Caption := 'Start!'; Button1.TabOrder := 10; 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 SetupAll; begin Username := Edit1.Text; Password := Edit2.Text; end; begin SafeInitForm; SafeShowFormModal; SetupAll; WriteLn('Username = ' + Username); Writeln('Password = ' + Password); end. Congratulations! You just made a form!! Deathader: All programmers can look in the programmer forum to learn how to make a form have AUTH capeabilities
hey hey deathader i was wondering if its possible to make a set of instructions/code invisible when the script has been executed...for example: I wanted my script to open a webpage but when the script was playing it wouldn't show the webpage being opened..