I need to use a globally declared array in my script, but Scripter gives a Syntax Error on the standard pascal syntax declaring the array.
KOPF2 : Array [1..300] of string ;
The documentation says arrays are supported, but all of the examples provided are of implicitly declared arrays. (I do not want to set OptionExplicit to true, and it wouldn't work for a global anyway.) Is there a way to explicitly declare an array, or do I have to create the array outside of Scripter and use DefineProp to make it available to the script?
All variables in scripter are variants and typeless. You can't (and don't need) to declare a variable as array. You just create an array and assign the array to the variable.
First, a clarification: I misstated in my original post. I do need to use OptionExplicit = true.
Second, a little more background on my use of Scripter: I am replacing an existing script engine in my application. I need all of my existing scripts to continue to work with a minimum amount of modification to those scripts. I also need to try to maintain script compatibility with the previous scripting engine (at least in the short term).
Are you saying I should create an array in the script, or do you mean create an array in the host application? Can you elaborate on how you would do this?
You don't need OptionExplicit = true. You can just declare the variable with any type, or no type at all (just the name).
You can create the array in both script or host application. But as said, they are variant arrays. You can construct it from script using VarArrayCreate (like in Delphi), or using specific TMS Scripter array constructor:
MyArrayOfString := ['one', 'two', 'three'];
I understand what you are saying. With the constraints I have in this situation, the script based approach is not viable because it requires script modification that can break backward compatibility with the old scripting engine. To make TMS Scripter work with our existing scripts I will have to find array declarations in the script before compile, parse them out and create the array in the host application.
It would be great if TMS could recognize the standard Pascal array declaration syntax and create an equivalent variant array from it.
Thanks for your help!