1 (edited by rbknathan 2020-08-19 05:07:08)

Topic: Splitting the script file

I am trying to have script separated by forms and separate script to maintain common functions/procedures.

But its showing error. Have all the 3 files in 'Script' folder of the project. Please advice me on this.

---------------
file - script.pas
----------------
uses 'form1.pas', 'common.pas';
//uses 'common.pas';

var
  sHello: string;

begin
  // just for example
  sHello := 'Script said hello!';
  HelloWorld(sHello);
end.     

----------------
file - common.pas
----------------
procedure HelloWorld (s: string);
begin
  ShowMessage(s);
end;

---------------
file - form1.pas
----------------
uses 'common.pas';

procedure cb_Button1_OnClick (Sender: TObject; var Cancel: boolean);
var
begin
     HelloWord('Hello from form1');
end;

Post's attachments

Attachment icon script.JPG 20.44 kb, 129 downloads since 2020-08-19 

2 (edited by brian.zaballa 2020-08-19 05:33:45)

Re: Splitting the script file

Just add begin end on the last part of your external pas (form1.pas and common.pas)

procedure HelloWorld (s: string);
begin
  ShowMessage(s);
end;

begin
end.
brian

3 (edited by rbknathan 2020-08-19 05:43:08)

Re: Splitting the script file

Thank you brian.zaballa.

It worked. :-)


While searching about this, I came across the 'Unit' Concept.

https://wiki.freepascal.org/Unit

Unit approach is not working. Is it supported ?

Re: Splitting the script file

rbknathan wrote:

Thank you brian.zaballa.

It worked. :-)


While searching about this, I came across the 'Unit' Concept.

https://wiki.freepascal.org/Unit

Unit approach is not working. Is it supported ?

Haven't tried this yet but it seems interesting. I need that one. I'm novice when it comes to pascal. smile I hope someone can give us any idea on it. Meanwhile, I gotta search on making this one work.

brian