DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

How to declare a persistent class in diadem?

Solved!
Go to solution

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.

0 Kudos
Message 1 of 7
(5,401 Views)
Solution
Accepted by topic author tlahoz

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?

Message 2 of 7
(5,381 Views)

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.

0 Kudos
Message 3 of 7
(5,366 Views)

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

Message 4 of 7
(5,341 Views)

Hi mr Turpin,

 

Thank you, we found it the other day and began working around it. It's proven to be quite useful.

0 Kudos
Message 5 of 7
(5,331 Views)

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?

0 Kudos
Message 6 of 7
(5,183 Views)

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

0 Kudos
Message 7 of 7
(5,105 Views)