07-20-2012 05:10 AM
Greetings,
I've been working with extensive scripts in diadem. I've found classes being a big help keeping the code clean and somewhat legible.
Now I'm trying to make a next step, creating a class that carries it's info between different scripts.
If I create this class in a script and then call another script, the public methods of the class can be executed by the next scripts. But if I create the class (as a global variable with GlobalDim) in a subscript called, the methods cannot be called by the parent script, it says it's an undefined variable. Neither works when we call the methods from a dialog.
Is there any method to make a class methods available to all the execution scope?
Thanks.
PS: We're using diadem 10.2, don't know if it changes with the next versions.
Solved! Go to Solution.
07-23-2012 06:18 AM
As far as I know GlobalDim is not capable to create objects. So I assume with DIAdem 10.2 there is no ability to create a global object.
In current DIAdem versions its possible to register scripts as user commands. They can also contain instanciations of classes that will be available globally.
If you put this code into a user Command file (Settings -> Options -> Extensions -> User Commands)
class PMType
public Hersteller
public Typ
End Class
dim PM : set PM = new PMType
PM.Hersteller = "NI"
the PM variable is globally availables?
07-25-2012 03:22 AM
Thanks!
It's available. But it has the problem you have to register the script, so it won't be easily deployed as part of the application... guess we'll have to think about it.
07-30-2012 11:36 AM
Hi tlaHoz,
You can dynamically register user commands by running the ScriptCmdAdd() command. It will return synchronously once the user commands are registered, after which you can use them in the rest of that script or any others afterwards. I usually use this approach to register any needed user commands, in combination with the AutoActPath variable or the newer CurrentScriptPath variable to make the whole application portable.
Brad Turpin
DIAdem Product Support Engineer
National Instruments
07-31-2012 02:18 AM
Hi mr Turpin,
Thank you, we found it the other day and began working around it. It's proven to be quite useful.
10-19-2012 11:53 PM
Ok now you created a global class, but how do you see the members of the class when you are in the main script and type and period after the object?
10-30-2012 05:18 PM
Sorry James,
That's not implemented as of DIAdem 2012. Your only option right now is to temporarily copy the content of the global class into the main script while you need to use intellisense.
Brad Turpin
DIAdem Product Support Engineer
National Instruments