Explanation of Object Pascal types

TURBU

Explanation of Object Pascal types

 

Back to RPG Script Reference

 

Integer types:  Several different types of integers are used in Object Pascal.  They differ in two factors: how many bytes are used to store the data, and whether the number is signed (allowed to be either negative or positive) or unsigned (only zero and positive numbers).  Types with more bytes can represent a wider range of numbers, but take up more memory.  Likewise, unsigned types can represent numbers twice as large as signed types of the same byte size, by sacrificing the ability to represent negative numbers.

 

Byte:  Unsigned, 1 byte.  Range: 0..255

Shortint: Signed, 1 byte.  Range: -127..128

Word: Unsigned, 2 bytes.  Range: 0..65,535

Smallint: Signed, 2 bytes.  Range: -32,768..32,767

Cardinal: Unsigned, 4 bytes.  Range: 0..4,294,967,295

Integer: Signed, 4 bytes.  Range: -2,147,483,648..2,147,483,647

 

Enumerated types:  A set of names that each represent a number, but which is generally restricted to a far smaller set size than integer types provide.  They are used by the programmer as a mnemonic device to make certain sets of data easier to remember and refer to.  For example, instead of numbering a hero's slots as 1..5, they are represented by an enumerated type using the names of the slots.  Enumerated types are declared using a list of names separated by commas, within parenthesis.

 

String:  A sequence of letters, used to represent text.  A literal string (actual string data, not a string variable) used in a script must be enclosed in 'single quotes', so the computer knows it's looking at a string and not a variable name or enumerated type identifier.  "Double quotes" and curly "smart quotes" generated by word processors will not work.  Only straight 'single quotes' are accepted by the script compiler.

 

Array:  A group of variables of the same type, arranged in an ordered sequence.  In Object Pascal, arrays are declared with the word "array," then an optional range declaration in square brackets, then "of <variable type>".  So an array of ten word variables would be defined as: array [1..10] of word, and an array of integer variables with no predetermined length would simply be: array of integer.

 

Object:  A group of variables which are not all of the same type, grouped together to form a larger, composite variable.  Objects are used to represent a single item with many different attributes.  Objects also contain routines for managing the variables that they contain.  An object's routines are known as methods, and its variables are usually hidden from direct access by the object's programmer.  Instead, the variables are accessed through properties, an interface that looks like variables to the person using the object, but which may actually contain routines to process information behind the scenes when reading or changing it.

For example, the Hero object's "hp" property reads directly from the variable, but when a script changes its value, that value is first checked to make sure that it's valid (not negative and not higher than the hero's maximum HP), corrects the value if necessary, then assigns it to the real variable.  Then it checks if the value it assigned is 0, and if so, it sets the "dead" condition on the hero.  But all this happens behind the scenes; all the RPG Script writer has to do is change the property as if it were a normal variable.

This help file was created with the free trial version of HelpScribble.