Class - Defining a Class
Navigation: PGMs ➔ Classes
Functions | Subroutines | Classes | |||||
---|---|---|---|---|---|---|---|
Defining a Function | Predefined Functions | Tag Functions | Mathematical Functions | String Functions | Defining a Subroutine | Trigger Subroutines | Defining a Class |
Related Links: User Defined Class and Functions, Example PGM Files
Class - Introduction | Class - Defining a Class | Class - Using a Class | Class - Macros | Class - Examples |
---|
Global Predefined Class Instances: Species Database Class, Particle Size Definition Class, Plant Model Class
Predefined Classes: Array Class, StrArray Class, Matrix Class, TagSelect Class, Noise Class, TimeClass
How to Define a Class
Class className
;Variable declaration(s)
;Sub(s) and Function(s)
EndClass
|
|
Syntax for Class Declaration
Function | Function Syntax | Description/Notes/Example | |||
---|---|---|---|---|---|
Declaring a Class | Class ClassName
;Class code
EndClass
|
| |||
Class Variable Declaration | For Variable Declaration Syntax, refer Variable declaration. |
Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class.
| |||
Syntax for Subs and Functions | Sub SubroutineName()
Function FunctionName()
StrFunction StrFunctionName()
|
Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.
Typically, a class will have these three types of subroutine in it:
| |||
Special Functions |
ClassName()
|
This Special Function is available for use within class functions and subroutines. ClassName returns a string of the class type name. In example below, this will return "CSTR_Class". | |||
ClassTag()
|
This Special Function is available for use within class functions and subroutines. ClassTag returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model.
For example, we can use | ||||
Special Functions -
General Keywords |
ClassAsGroup
|
If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window. | |||
ClassAsPageLabel
|
Available from Build 139.31388. If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page. | ||||
ClassAsTextLabel
|
If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name. | ||||
Specal Functions -
Grid Display Keywords |
ClassGridColumnWidth Width
|
Use this keyword to change the width of each column displayed in a grid class. | |||
ClassGridMaxColumns MaxColumns
|
Use this keyword to change the maximum number of columns allowed before a new grid is automatically created. | ||||
ClassGridHideComment
|
Use this keyword to hide the display of class instance comments that are normally displayed in the first row of the grid. | ||||
ClassGridHideText
|
Use ths keyword to hide the display of all TextLabels shown a text between rows in the grid. | ||||
Alternate Special Functions - Used outside of the Class definition. As Grid Display Keywords. See Class Variable Display Options for more information and display examples.
|
Class Declaration Example
- A very condensed extract of the CSTR_Class PGM file is presented below to explain the structure and use of the Class definition:
Class CSTR_Class
ClassAsPageLabel ;example of Special Keyword
;... Various Variable Definitions.....
String UnitTag{tag}@
Real TankVolume*("Vol","m^3")<<300>>
;... Various Variable Definitions.....
Sub Init()
UnitTag = ClassTag() ; example of Special Function
[concatenate(UnitTag, ".ResTime.Volume (m^3)")] = TankVolume
EndSub
Sub CalculateCSTR()
;......Various Calculation Code .....
EndSub
Sub Exec()
;......Various Calculation Code .....
CalculateCSTR() ;Example of calling a predefined subroutine within a subroutine.
;......Various Calculation Code .....
EndSub
EndClass
- The name of the Class (or template) is called CSTR_Class.
- All the variables that are associated with the CSTR_Class are defined. (The full PGM file is available in the Gold distributed example project)
- Nested functions are allowed within a class, for example Sub "CalculateCSTR" is called inside the Sub "Exec()"
- In summary, the Class(template) "CSTR_Class" contains a number of calculations and a number of Set Value Commands.