How to check if a variable exists or has been shared from the main program

From Delphi I call, recursively, a PascalScript.

The second call and so on, I call the PascalScript, the variables shared with the scripts are all here, because they are the ones of the Parent object. My problem becomes in the first call: the variables of the parent doesn’t exists.

Are there a mode of check if a variable exists or was been shared to evaluate if I can use it or should assign a default value instead?

Thank you very much!

There’s a GetVar2 api on TPSExec that can tell you if a var exists.

Sorry, but what I need is from inside of the script.
As part of the script something like : if exists(VARIABLE_X) then begin…

No it would fail already before that, it wouldn’t even compile.

you may use a Function which is implemented in Delphi, and it takes the Var-Name as Parameter and returns the Value of the Var as String.
If the Var is not defined, the Function may return an empty string - or whatever you need.