PDA

View Full Version : Need help in forms!



Pentti
11-04-2006, 08:38 AM
I need help in making forms. I tried to do easy examples, but when i run the script it says:
Runtime Error] : Exception: Cannot make a visible window modal in line -- in script
Anybody knows what did I do wrong? Can somebody do me example how to make form where you can put your player name and then it reads it from form to here:
procedure DeclarePlayers;
begin
Players[0].Name :=(The name from form);
end;
Please can somebody help me.

Starblaster100
11-04-2006, 12:28 PM
(The name from form).Visible := True
to
(The name from form).Visible := False;

Pentti
11-04-2006, 02:15 PM
Lol. Thanks very much!!! That helped me alot!
Can you tell me how can i make my "OK" button to Close form window?
Here's my code:
program New;
{.include srl/srl.scar}
var
frmDesign : TForm;
Name : TEdit;
Ok : TButton;

procedure InitForm;
begin
frmDesign := CreateForm;
frmDesign.Left := 250;
frmDesign.Top := 114;
frmDesign.Width := 158;
frmDesign.Height := 190;
frmDesign.Caption := 'frmDesign';
frmDesign.Color := clBtnFace;
frmDesign.Font.Color := clWindowText;
frmDesign.Font.Height := -14;
frmDesign.Font.Name := 'MS Sans Serif';
frmDesign.Font.Style := [];
frmDesign.Visible := false;
frmDesign.PixelsPerInch := 120;
Name := TEdit.Create(frmDesign);
Name.Parent := frmDesign;
Name.Left := 10;
Name.Top := 35;
Name.Width := 121;
Name.Height := 24;
Name.Hint := 'Player name';
Name.TabOrder := 8;
Name.Text := 'Name';
Ok := TButton.Create(frmDesign);
Ok.Parent := frmDesign;
Ok.Left := 39;
Ok.Top := 86;
Ok.Width := 46;
Ok.Height := 27;
Ok.Caption := 'Ok';
Ok.TabOrder := 9;
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 Declareplayers;
begin
HowManyPlayers:=1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer:=0;
Players[0].Name:=Name.Text
end;

procedure WriteName;
begin
writeln(Players[0].Name)
end;

begin
SafeInitForm;
SafeShowFormModal;
setupsrl;
DeclarePlayers;
WriteName;
end.


EDIT:
I found out it myself.

CamHart
11-04-2006, 03:05 PM
This is a crappy way of doing things, but i use it for beta scripting purposes :D. Readln FTW!

Starblaster100
11-04-2006, 05:22 PM
Get ready for a long post ;) :

To make a button, you need to make a special type of Procedure called a sender. Its basically a procedure which works on a form.

so:



Procedure ClickTheOKButton(sender: TObject);
Begin
(The name from form).Caption := FrmAth.Caption+'.'; //This adds a 'Period' to the end of the title. Its so if something goes wrong, you can see what, but most of the time its useless.
(The name from form).ModalResult := mrOk; //Tells the script that everything is A-OK and we should carry on.
end;


Now to the main form procedure:


Ok := TButton.Create(frmDesign);
Ok.Parent := frmDesign;
Ok.Left := 39;
Ok.Top := 86;
Ok.Width := 46;
Ok.Height := 27;
Ok.Caption := 'Ok';
Ok.TabOrder := 9;
OK.OnClick := @ClickTheOKButton; //Ive added this line. this says when the button is clicked, calle the ClickTheOKButton procedure.


And thats a button done.

The only bad thing about it though is that if you were to press the X button on the form to close it down the script would still continue. So here is what i added. A global Variable called ScriptStart:



Var
ScriptStart: Boolean;

Procedure ClickTheOKButton(sender: TObject);
Begin
(The name from form).Caption := FrmAth.Caption+'.';
(The name from form).ModalResult := mrOk;
ScriptStart := True;
end;

Procedure InitForm;
Begin
//The usual Stuff here
end;

//3 boring procedures here all forms need, which you already have

//mainLoop:
Begin
SafeInitForm;
SafeShowFormModal;
If(ScriptStart = False)then
TerminateScript;
setupsrl;
DeclarePlayers;
WriteName;
end.


Now this means that ScriptStart will only be set to true if that button is clicked. If not, it will be false and hence the script will terminate

Thats all

Good luck scripting!

Pentti
11-04-2006, 06:15 PM
This is great! Thank you for helping with this!