Please enable JavaScript to view this site.

DAQFactory User's Guide

Navigation: 5 Sequences & Scripting > 5.20 Object Oriented Programming

5.20.3 Creating Objects without Classes

Scroll Prev Top Next More

The class is like a cookie cutter, so is great if you need to create a bunch of objects of the same type.  You can also create an object without specifying a particular class if you just want to create a simple structure. This is done using the web standard JSON format.  For example, we could also create Frank like this:

 

global Frank = {"name" : "Frank Smith", "address" : "123 Main St", "zip" : "12345"}

Using this method is convenient for just create structures, especially for passing to and from other functions.  

 

The JSON parser uses standard JSON, not DAQFactory syntax, so a few points about using this method:

 

Objects created this way are just structures.  They cannot have member functions (described below), and any embedded objects also need to be declared this way.  Also, all the assignments have to be constants.  You cannot include variables.  So, for example, this will fail:

 

global name = "Frank Smith"

global Frank = {"name" : name, "address" : "123 Main St", "zip" : "12345"}

 

All member variables must be identified in quotes.  So this is also invalid:

 

global Frank = {name : "Frank Smith", address : "123 Main St", zip : "12345"}

If you specify arrays, you must use JSON notation using square brackets instead of the DAQFactory standard {}.  So:

global x = {myArray : [3,4,5]}

Likewise, you cannot use the DAQFactory helpers such as 0x for hex values, 0b for binary, HMS date notation, any sort of math, etc.

That all said, once the object is created you would use all the standard DAQFactory methods for changing the member variables.  For example this is ok:

 
global name = "George"

global Frank = {"name" : "Frank Smith", "address" : "123 Main St", "zip" : "12345", code : 4}

Frank.name = name

Frank.code = 0x0f