Global variable not working.

Hello NewsGroup,

the following code does not work in  TMS-Script:
(it's an empty form without any components)

{$FORM TForm1, Example_GlobalVar_with_Form.sfm}

uses
  Classes, Graphics, Controls, Forms, Dialogs;

var
MyGlobalVar:integer;
Form1:TForm1;

procedure Form1Show(Sender: TObject);
begin
  showmessage(format('Form1Show: MyGlobalVar=%d',[MyGlobalVar]));
end;
                                
begin
  MyGlobalVar:=1000;
  Form1:=TForm1.create(nil);
  try
    Form1.showmodal;
  finally
    Form1.free;
  end;
end;

Error is: Runtime error (Line 12, Col 64): File library Example_GlobalVar_with_Form: Illegal argument to Format function when evaluating instruction CallProc ($1,$2,$6F3274,$328D590,'format').
Stack content is: [Integer:102327728,Null,Null].

Is this a bug?
Any suggestion for a "workaround".

Thank you.

A "global variable" in a form is considered a property of the form class. It means that there is a new MyGlobalForm for each instance of Form1. You should not mix "global" code with form code. In scripture, that whole unit represents a form instance. This code works:




{$FORM TForm2, Unit2.sfm}


uses
  Classes, Graphics, Controls, Forms, Dialogs;


var
  MyGlobalVar:integer; 
  Form2:TForm2;


function Form2Show(Sender: TWinControl; C1, C2: TControl): Boolean;
begin
  showmessage(format('Form1Show: MyGlobalVar=%d',[MyGlobalVar]));
end;


procedure Form2Create(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
  MyGlobalVar:=1000;  
end;


begin
  Form2:=TForm2.create(nil);
  try    
    Form2.showmodal;
  finally
    Form2.free;
  end;
end; 


But the ideal is that you simply remove that initialization code from the form unit, and instantiate the TForm1 (TForm2 in my code) object from an external script.
Thank you,
I could solve this issue.

Until now we used DreamScript. With DreamScript it was possible to have all in one file.
With TMS Scripter we must split the form-stuff into a seperate file.
Since the script is stored in the Database, we had to change now the storage as well.

But problem it's solved now.
Thank you for your support.