Frequently Asked Component Specific Questions
Displaying items 1 to 2 of 2, page 1 of 1
<< previous next >>

TMS Scripter: Saving/Loading compile code for scripter projects
(Feb 11, 2009)
When using standard Scripter component with a single script, you just need to call SaveCodeToFile and LoadCodeFromFile methods of scripter component to handle compiled code.
When it comes to multi-script project using the Scripter Studio Pro engine, you must write extra code and save compiled code of all units (scripts). It's the same for loading: you must load compile code of all units.
This is a pseudo-code example for saving compiled code:
for c := 0 to IDEEngine1.Files.Count - 1 do
begin
if not IDEEngine1.Files[i].Script.Compiled then
IDEEngine1.Files[i].Script.Compile;
AUnitName := IDEEngine1.Files[i].Script.ScriptInfo.UnitName;
IDEEngine1.Files[o].Script.SaveCodeToFile(ABasePath + AUnitName + '.code');
end;
To load the code, you just do the reverse. Pay attention to add directories to the search path where the compiled code is located, because scripter tries to load the compiled code for used units on the fly (if you load Unit1 and it uses Unit2, it tries to load Unit2 code by searching files in search path). Example:
with IDEScripter1 do
begin
{By setting the LibOptions properties below, you just need to load the script code for the main unit}
LibOptions.UseScriptFiles := true;
LibOptions.SearchPath.Add(SomeSearchPath);
LibOptions.CompiledFileExt := '.code';
Scripts.Clear;
{Load main unit only - the other units will be loaded on the fly based on the LibOptions settings}
AddScript(slPascal).LoadCodeFromFile(ABasePath + MyMainUnitName + '.code');
Execute;
end;
Wagner Landgraf (Feb 11, 2009)


TMS Workflow Studio: Registering components and methods in workflow scripting system
(Mar 2, 2009)
The Workflow Studio manual describes how to register new components, methods, classes and properties to a scripter component by using methods like DefineClass, DefineProp, etc..
However, Workflow Studio creates a new scripter component instance for each script block that is used in a workflow instance. Due to that, you must use OnGlobalScripterCreate event to make sure you initialize all scripter components in the system. The following steps show how to do that.
The OnGlobalScripterCreate is a global variable of type TNotifyEvent declared in atScript.pas unit. First of all, you need to set that global variable to a method in your application:
{PrepareScripter is a method in any of your existing and instantiated classes}
OnGlobalScripterCreate := PrepareScripter;
Then you declare your global initialization method PrepareScripter. The Sender parameter is the scripter component, so you just need to typecast it to a generic TatCustomScripter class. Here is an example:
Procedure TMyDataModule.PrepareScripter(Sender: Tobject);
begin
With TatCustomScripter(Sender) do
begin
AddComponent(Form1);
end;
end;
Wagner Landgraf (Mar 2, 2009)