If it’s not documented, no one has made this and do not exists an example… It’s not possible, true?
The conclusion is that we can’t insert, from out of the Script, variables that does not exists in the host program, to be used inside the script, and recover finally his values from outside the Script.
Thank you!
Don’t works. You only need to read my ask to this.
function TConfigCompOrm.EvaluatePair(Pair :TCalcPair):TField;
var Parser :TMathParser;
FScript := TPSScript.Create(nil); { Create an instance of the ScriptPascal }
FPair := Pair;
FScript.OnCompile := OnScriptCompile;
FScript.OnExecute := OnScriptExecute;
try
if not FScript.Compile then begin
Pair.Result.Clear;
Result := Pair.Result;
raise Exception.Create(Pair.Result.FieldName +’: ‘+ FScript.ExecErrorToString+’ '+FScript.ExecErrorParam);
end
else begin
FScript.Execute; // Run the script.
Result := Pair.Result;
end;
Result := Pair.Result;
finally
FScript.Free;
end;
procedure TConfigCompOrm.OnScriptCompile(Sender: TPSScript);
begin
if FPrecursor is TItemOrm then begin
FScript.AddRegisteredVariable(‘QTY_QUANTITY’, ‘Extended’);
FScript.AddRegisteredVariable(‘CD_COMPONENT’, ‘String’ );
RegisterVariablesFrom(TItemOrm(FPrecursor));
end else
if FPrecursor is TConfigCompOrm then begin
RegisterVariablesFrom(TConfigCompOrm(FPrecursor));
end;
end;
When Just after “if not FScript.Compile then begin” that should register…
FScript.AddRegisteredVariable(‘QTY_QUANTITY’, ‘Extended’);
FScript.AddRegisteredVariable(‘CD_COMPONENT’, ‘String’ );
An exception says: QTY_QUANTITY :No Error.
Ah!!! the script don’t make reference to CD_COMPONENT…