Browse
(440) 299-7778
Menu
(440) 299-7778
One-year parts and labor warranty30-day money-back guaranteeEnglishEspañolContact

The text of a manual · part 6 of 18

Qlarity-Based Terminal Programmer's Reference Manual: Chapter 2 Qlarity Language Syntax, pages 26 to 32

Pages 26 to 32 of 134, from Qlarity-Based Terminal Programmer's Reference Manual

The original document is the PDF (1.5 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.

Filed in the catalog under the QSI Corp QTERM-G70

Page 26

14

QSI Qlarity-based Terminal Programmer’s Reference

Variables declared inside the function are local to that function and cannot be accessed from outside the function.

2.12.2 Private, Protected, and Fixed Functions Syntax:

The “returns” clause specifies the type of value that is returned from the function. If a returns type is specified, then the function is required to return a value of that type. The value is passed back from the function using the “return” statement, which also terminates the function. Multiple “return” statements can be included in a function in separate execution paths. The first “return” statement executed will end the function. Return statements with no value may be used to terminate a function with no return value. Functions with no return value have an implied return at the “endfunc” statement. The actual code for the function is entered between the local variable declarations and initialization (if any) and the “endfunc” statement.

private func <name> (<parameters>) [...] endfunc protected func <name> (<parameters>) [...] endfunc fixed func <name> (<parameters>) [...] endfunc protected fixed func <name> (<parameters>) [...] endfunc

Description: Example: func getChar(data[] as byte) returns boolean handles msg_comm_receive dim newData[5] as byte init newData := [10,20,30,40,50] dim countdown, countup as integer init countup := 0 if len(data) == 5 for countdown = 4 to 0 step -1 newData[countup] = data[countdown] countup = countup +1 next endif return true endfunc

2.12.1 Calling a Function Use the following syntax to call a function:

A function can be declared private or protected. A function that is declared private can be used throughout the definition of an object but cannot be overridden and cannot be called from outside the object definition. A protected function may be accessed in the object template and in the declaration of an object instance of that template (i.e., in override functions within the instance). Protected functions may also be accessed by templates that extend (inherit from) the template in which they are defined. No other access is allowed. A function can also be declared fixed or protected fixed. A fixed function cannot be overridden. A protected fixed function cannot be overwritten either in an instance of the template or in another template that extends the template which defines the fixed function. Additionally, the protected fixed function, like a protected function, may only be used my instances of the template and by other templates which extend the template.

<funcname>(<parameter>, ...)

Use the following syntax to call an object method: <objname>.<funcname>(<parameter>, ...)

The parameters to call a function can be literal values, variables of the correct data type, or expressions that produce the correct data type.

2.12.3 Validation Methods A very powerful and useful feature of Qlarity is the validation method. These special functions are tied to variables (usually object properties). When the variable is assigned a value using the validation assignment operator (=), the validation method is implicitly called and passed the new value as a parameter. This allows the object property or global variable to perform validation on the new value (e.g., is the value within allowable bounds?) and to perform other

QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770

Page 27

QSI Qlarity-based Terminal Programmer’s Reference actions that update the state of the object or variable in the application. Qlarity objects derive much of their power from this feature. For example, a simple area object might have properties defining the location of the object on the display. The validation methods for the x- and y-position properties might check to make sure that the value is within the boundaries of the screen and call Qlarity API functions to redraw the object at the new location. All of this occurs from simple assignment of a new value to the object property. A validation function must have the same name as the variable being validated. Also, there can be only one parameter to the function, and it must be of the same data type as the associated variable. Otherwise, these functions have the same syntax as normal functions.

Example: dim array1[10], array2[20] as integer array1 = array2

If a validation function for “array1” exists, it will be called and passed to “array2” as a parameter. Example: dim myarray[10] as integer func myarray(newarray[] as integer) if len(newarray) > 10 then myarray := newarray endif endfunc

2.12.5 Array Element Validation Functions

IMPORTANT: Do not use the validation assignment operator on the validated variable within the validation method! This will recursively call the validation function until the system software gives an exception.

Syntax:

Example:

Description:

dim x as integer dim flag as integer func x (newval as integer) if newval > 20 & newval < 100 then x := newval else flag := -1 endif endfunc

15 func <array_name>[] (<new_value> as -> <data_type>, <index> as integer) [statements...] endfunc

These functions are called whenever an element of an array is assigned a new value with the validation assignment operator. The “<index>” parameter contains the index of the array that is being assigned a new value. Example: dim myarray[10] as integer

In this example, if the new value being assigned is not between 20 and 100, then flag is given -1 and x retains its old value. If no new value is assigned to the variable during its validation function, then it will retain its old value. 2.12.4 Array Validation Functions Syntax: func <array_name> (<newarray>[]as -> <data_type) [statements...] endfunc

These functions are called when the entire array is assigned a new value with the validation assignment operator.

func myarray[](newval as integer, index -> as integer) if index == 0 then if newval > 10 then myarray[index] := newval endif endif endfunc

2.12.6 Reference Parameters Syntax: func <func_name> (<varname> as reference -> to <datatype>) [...] endfunc

QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770

Page 28

16

QSI Qlarity-based Terminal Programmer’s Reference

Description: Qlarity normally uses a pass by value convention, which means that functions receive a copy of variables passed as parameters. They cannot modify the value of the original variable. Reference parameters make it possible to modify the values of the variables that are passed into a function as parameters. These are especially useful when a function needs to return more than one value. Example: func myFunc(newVar as reference to integer) newVar=5 endfunc

When “myFunc” is executed, a reference to the variable is passed into the function. The value of “newVar” reflects the change after the function returns.

2.13 Conditionals (if Statement) Syntax: if <boolean_expr> then [...] [elseif <boolean_expr> then] [...] [else] [...] endif

The “then” is required. The “elseif” and “else” statements are optional. There is no limit to the number of “elseif” clauses that can be added to the “if” statement Example: dim x as integer if x < 10 then x = x +1 elseif x == 10 then x=x+2 else x=x-2 endif

2.14 Looping and Leaping 2.14.1 For/Next loops Syntax:

[...] next

Description: The “for” loop executes starting with “<name> = <start_expression>” and increments “<name>” by the amount specified in “step” until “<name>” is equal to “<stop_expression>.” “Step” may be positive or negative. If no “step” is specified, “<name>” is incremented by 1. When “<name> = <stop_expression>,” the loop executes for the last time. If “<name>” has a validation function, it is called each time through the loop. When the loop terminates, “<name>” will have been incremented or decremented beyond “<stop_expression>.” (In the example below, the final value for “countdown” is -1.) Also, “<stop_expression>” is evaluated each time through the loop. If “<stop_expression>” is complex or involves a function call, and the value of “<stop_expression>” does not change, it is recommended that you store the value of “<stop_expression>” in a variable and use that for “<stop_expression>.” Example: dim Data[5] as byte init Data := [10, 20, 30, 40, 50] dim stepamount as integer init stepamount := -1 dim countdown, countup as integer init countup := 0 for countdown = 4 to 0 step stepamount newData[countup] = data[countdown] countup = countup +1 next

2.14.2 While Loops Syntax: while <boolean_expression> do [...] loop

Description: The statements inside the “while” loop are executed until the boolean expression becomes false. If the boolean is false before the “while” loop starts, then the loop is not executed.

for <name> = <start_expression> to -> <stop_expression> [step <expression>]

QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770

Page 29

QSI Qlarity-based Terminal Programmer’s Reference

2.14.3 Do/While Loops

17 ment in the “on error” block with no option to return to the previous execution point.

Syntax: do [...] loop while <boolean_expression>

Description: The “do/while” loop is similar to the “while” loop except that it will always execute at least once. The boolean expression is evaluated each time execution reaches the end of the loop. When the expression becomes false, the loop is finished. 2.14.4 Goto/Label Syntax:

Within the “on error” block, the application can retrieve the last exception using the GetException() API function. Code in the “on error” block is intended to handle exceptions in a manner defined by the application. If the “on error” block doesn’t resolve the exception, it can call Rethrow() to allow a higher level “check error” to handle it. If no “check error” block appears in the function, the error “bubbles up” to the function that called it and eventually out to the system where MSG_ERROR functions can handle it. For more detailed information on exception handling, refer to the section onf “Exception Handling in the Qlarity Foundry User’s Manual.

goto <label_name>

2.16 Defining Objects label <label_name>

Syntax: Description: The “goto” command is used to stop executing the code at the “goto” command and begin where the “<label_name>” is specified. The “label” command is used to mark a spot to be jumped to with the “goto” command. These two statements must appear within the same function. Jumping between functions is not allowed. Also, you cannot jump into, out of, or between different “check error” blocks. It is generally good coding practice to avoid “goto” whenever possible.

2.15 Exception Handling Syntax: check error [...] on error [...] enderr define <object_type> type <name> [extends -> <Name>] [...] enddef

Description: An object type must be defined in order for an instance of that object to be declared. Object properties are defined using “dim” statements. Default values are assigned using “init” statements. Methods are defined by putting function definitions inside the definition of the object. Any instances of an object type will have these properties and functions. “<object_type>” may be any of the three object type keywords: “object,” “area object,” or “container.” “<name>” may be any legal and unique identifier and becomes the name of the defined object type. "Extends" indicates that this template will extend the template <name>, where <name> is the name of the template this one will extend. By extending a template, the new template will inherit all methods and properties of the base template.

Description: The purpose of the “check error” block is to check for an error and then resolve the error. The code between “check error” and “on error” is executed normally. If an exception is thrown by the system or by using the Throw() API function, then execution immediately jumps to the first state-

Extending templates via inheritance can be a powerful tool to allow you to reuse existing code and create modified objects quickly. When extending templates there are several items to remember.

QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770

Page 30

18

QSI Qlarity-based Terminal Programmer’s Reference

• The extending template receives all of the base template’s variables and functions. Care should be exercised not to declare any variables or functions with the same name as those in the base template unless the extending template is overriding those elements

• The extending template may not access the base template's private variables and functions

• The extending template may override any variable declaration, variable initialization or function definition.

• When overriding a variable or function, the extending template may reduce the access to the element. For instance, a template may override a protected variable declaration in a base template as private. Conversely, it is not allowed to increase access to an element in the extending template. For example, you could not override a private function in a base template as protected in the extending template.

• An extending template may add validation functions for variables in a base template. The compiler will issue a warning for this unless you also override the variable in the extending template.

All functions and properties defined for an object type will be included in any instance of that type. Variables may not be created using a “dim” statement inside an object instance, but they may be given initial values for that instance using “init” statements. Functions declared in an instance must also have been declared in the object template; they will override the functions in the template. The function name, events handled, parameters, name, type, and return type must match the declaration of the function in the template. Chapter 10 in the Qlarity Foundry User’s Manual gives examples of defining an object type and creating instances of the object.

2.18 Level Syntax: Level <integer>

Description:

be validated by functions in the base template. As this is usually undesired behavior, the compiler will issue a warning in this case. To avoid the warning either rename the variable or override the validation function in the extending template.

The “Level” command specifies the Z-order of an instance at application startup. Instances with a higher level appear higher (towards the front) in the Z-order. If two instances have the same level, then their Z-order relative to each other is undefined. This directive must immediately follow a “declare” statement. Qlarity Foundry normally sets this directive based on the object’s location in the Object Tree.

Chapter 10 in the Qlarity Foundry User’s Manual gives examples of defining an object type and creating instances of the object.

This command is useful when writing Qlarity applications in a text editor. Qlarity Foundry typically ignores any Level commands typed in the Code View window.

2.17 Declaring Object Instances

2.19 Including Files and Resources

Syntax:

Syntax:

declare <name> as <defined_type> [...] enddec include "<file path>"

Description:

This includes the specified file to be compiled with your project. The “include” command is also used to make bitmaps, ttfonts, and bdffonts available as resources in the application.

• An extending template may add variables that would

Once an object type is defined, instances of that object may be created by declaring them. “<name>” may be any legal unique identifier; it is used to refer to the instance of the object. “<defined_type>” is the name of the object type, and it specifies the template to be used when creating the object instance.

Description:

Syntax: include bitmap "<bitmap_file_path>" as -> <name>

QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770

Page 31

QSI Qlarity-based Terminal Programmer’s Reference include ttfont "<ttfont_file_path>" as -> <name> include bdffont "<bdffont_file_path>" as -> <name>

Description: The “<name>” field is any name to be used to refer to the included bitmap, ttfont, or bdffont. If the keyword default is used as the name of the resource, then that bitmap, ttfont, or bdffont becomes the default resource of that type. Resource variables that are not explicitly initialized will receive the default resource. Since the backslash (\) character is a special character used in strings, it is necessary to use either a single forward slash (/) or a double backslash (\\) to separate directories in file paths.

2.20 Libraries Libraries are similar to other files that can be included except they may contain more than just source code. A library may contain any of the following:

• Qlarity source code • Native source code • Bitmaps • BDF fonts • TrueType fonts • Modules To include a library: Syntax: Include library "<file_name>"

The library “natives.lib” is automatically included by the compiler. Do not manually include this file in your project. See Chapter 10 of the Qlarity Foundry User’s Manual for more information on libraries.

19

Description: “<library name>” is the name of the library in which the entry resides. This is generally different from the library file name. “<entry type>” is the type of entry in the library: source, bitmap, bdffont, ttfont, native, or module. “<entry name>” is the name of the library entry. By referencing the library entries explicitly, you can use only the entries you want. Qlarity Foundry may bring in certain library entries automatically. To determine the name of a library and the names and types of entries in it, refer to the documentation that came with the library, or view the library in Qlarity Foundry.

2.21 Precompile Directives 2.21.1 #if/#else/#endif Syntax: #if <option_name> [statements...] #else [statements...] #endif

Description: “#if” statements are used by the compiler to determine if an option has been declared. If so, the code between the “#if” and the “#else” or “#endif” is compiled into the project. Otherwise, the enclosed code is not compiled. Code in the “#else” section is compiled only if the option was not declared. #ifnot/#else/#endif is also a legal construct, where the code between the #if and the #else or #endif is compiled if the option is not declared. Otherwise, the enclosed code is compiled. Code in the #else section is compiled only if the option was previously declared. 2.21.2 #option Syntax: #option <option_name>

Including a library simply informs the compiler of the existence of the library. To use the code or other entries in a library, you must reference them explicitly, as shown below. Syntax: Library <library name><entry type><entry -> name>

Description: This function is used to define a keyword that will be checked by the “#if” statement. Unlike Qlarity variables, a “#option” declaration for a given keyword must be used before it can be examined by the “#if” statement.

QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770

Page 32

20

QSI Qlarity-based Terminal Programmer’s Reference

A common predefined option is “_TOOL,” which is defined if Qlarity Foundry is currently running the application. Code that should only run in Qlarity Foundry (and be excluded from the application that runs in the terminal) should be enclosed in an “#if _TOOL/ #endif” block.

2.21.6 #Visible Syntax: #Visible <true or false>

Description: 2.21.3 #Toolimage Syntax: #Toolimage <string of hexadecimal digits>

Description: This directive defines the icon used by a template and instances of the template in Qlarity Foundry. Qlarity Foundry automatically generates and updates the “#Toolimage” line for each template in a workspace. The line with the “#Toolimage” directive must follow a template definition statement, and it must appear before any code in the template. Manually editing a “#Toolimage” line is not recommended. This directive is ignored when a workspace is compiled with the command line compiler.

This directive informs Qlarity Foundry about the visible state of an object (i.e., whether an object should be displayed or hidden). Normally, Qlarity Foundry inserts or alters this directive whenever you click on the “eye” icon in the Object Tree. This directive is ignored when a workspace is compiled with the command line compiler. 2.21.7 #Lock Syntax: #Lock <true, false, or me>

Description:

#Hidden <dimension statement>

This directive informs Qlarity Foundry about the lock state of an object (i.e., whether an object or its children can be altered in Qlarity Foundry). Normally, Qlarity Foundry inserts or alters this directive whenever you click on the “lock” icon in the Object Tree. This directive is ignored when a workspace is compiled with the command line compiler.

Description:

2.21.8 #STPBuilderApp

2.21.4 #Hidden Syntax:

This directive informs the Qlarity Foundry compiler that the variables declared in “<dimension statement>” should not be displayed in the Object Properties list. This only applies to global variables and object properties; it has no effect on local variables in a function. This directive is ignored when a workspace is compiled with the command line compiler. 2.21.5 #Setfile Syntax:

Syntax: #STPBuilderApp

Description: This directive appears on the first line of a workspace that has been saved by Qlarity Foundry. It is ignored when a workspace is compiled with the command line compiler. 2.21.9 #endfile

#Setfile <line number> <filename>

Syntax: Description:

#endfile

This directive tells the compiler to change file names and line numbers for error reporting. The line number is immediately set to “<line number>.” Qlarity Foundry uses this directive internally and ignores any such directives typed in by the user. Altering these directives is not recommended.

Description: This directive instructs the compiler to immediately cease processing the current file. Any code after the “#endfile” directive is ignored.

QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770