Rice Lake iRite IDE User Manual

Page 18

Advertising
background image

14

920i

Programming Reference

The declaration section contains declarations defining global program types, variables, and subprograms. The
main code body, if present, is assumed to be the declaration of the program startup event handler. A program
startup event is generated when the instrument personality enters operational mode at initial power-up and when
exiting setup mode.

Example:

program MyProgram;

KeyCounter : Integer;

handler AnyKeyPressed;

begin

KeyCounter := KeyCounter + 1;

end;

begin

KeyCounter := 0

end MyProgram;

The

iRite

language requires declaration before use so the order of declarations in a program is very important.

The “declaration before use” requirement is imposed to prevent recursion, which is difficult for the compiler to
detect.

In general, it make sense for certain types of declarations to always come before others types of declarations. For
example, functions and procedures must always be declared before the handlers. Handlers cannot be called or
invoked from within the program, only by the event dispatching system. But functions and procedures can be
called from within event handlers; therefore, always declare the functions and procedures before handlers.

Another example would be to always declare constants before type definitions. This way you can size an array
with named constants.

Here is an example program with a logical ordering for various elements:

program Template; -- program name is always first!

-- Put include (.iri) files here.

#include template.iri

-- Constants and aliases go here.

g_csProgName : constant string := "Template Program";

g_csVersion : constant string := "0.01";

g_ciArraySize : integer := 100;

-- User defined type definitions go here.

type tShape is (Circle, Square, Triangle, Rectangle, Octagon, Pentagon,

Dodecahedron);

type tColor is (Blue, Red, Green, Yellow, Purple);

type tDescription is

record

eColor : tColor;

eShape : tShape;

end record;

type tBigArray is array [g_ciArraySize] of tDescription;

-- Variable declarations go here.

g_iBuild : integer;

g_srcResult : SysCode;

g_aArray : tBigArray;

g_rSingleRecord : tDescription;

Advertising
This manual is related to the following products: