Run script from command line

Hello,


I try to make an application that starts a script from my program's command-line parameter.

The reason is that I want the end user to run the script from the desktop by double-clicking on the script file without seeing other forms than the ones generated from the script.
All I have done is to create a datamodule with an IDEScripter and then run the following code:

procedure TDataModuleExecute.DataModuleCreate(Sender: TObject);
begin
  if ParamCount > 0 then with Scripter do begin
      LibOptions.SearchPath.Add('$(CURDIR)');
      LibOptions.SearchPath.Add('$(APPDIR)');
      LibOptions.SearchPath.Add(ExtractFilePath(ParamStr(1)));
      LibOptions.SourceFileExt := '.psc';
      SourceCode.LoadFromFile(ParamStr(1));
      Execute;
  end;

The script contains a form with a TBitBtn.

When I try to run the script I got the following runtime error 'Class TBitBtn not found'

What is missing here?

Hopefully someone can give me some help to get started.

Regards
Lars Magne Endresen






Hi Lars,


first of all, how are you running a script that is a form? Or do you mean the script uses other script forms? Why not use TIDEEngine and load/run the project itself, instead of a separated script?
Nevertheless, you must register TBitBtn class:

Registerclass(TBitBtn)

TIDEEngine component does it automatically when it's created. Alternatively you can just create a TIDEEngine component.
That works better, 
Now I have added a TTIdeEngine and executed the RunProject method and now the libraries are automatically loaded and the form in the script files shows up.  I have also moved the components to the Main form in my app, unless the script close down immediatly.  Setting ShowMainForm := false hides the Mainform so now it works as expected.
Thanks again for your help  :)

Regards
Lars Magne Endresen

Hi,
Is there an event or state I can use to close the Delphi application when the user closes the main form in a running script. 

Script forms are just regular forms, so you have to set an event handler for OnClose event, or create a descendant of TScriptForm and add your own logic to it (then register the new class as the default class for all forms in script)