Fields - type and size


field_id, [“heading”], type & size [[dim1 [, dim2 [, dim3 [, dim4]]]]] \
[/logical] [,”format” [, flags [, “validation”]]]

The type and size of a key or data field in a record layout, or of a temporary field, is specified in two parts:

1

A single alpha character which indicates the field type, e.g. a=alphanumeric.

2

A number which indicates the size of the field in bytes, e.g. 20=20 bytes.

The two parts are concatenated to form the full type and size specification: a20.

The only type/size combinations that can be used in a data dictionary are: a1-a255, i2, i4, n4.0, n8.0, r8 and u1. Since Sculptor version 6.1.0 the b1-b255 can also be used on data dictionaries.

Since Sculptor version 6.2.0 the i8 and u8 have been added. The i8 is also supported in data dictionaries.

All types listed in the table below are valid for use with temporary fields. Note also that the data_type clause can be used in some circumstances to change fields at run time to types not supported by data dictionaries.

The valid field types are as follows:

Type

Size

Description

a

0-255

Alphanumeric. This field type may contain any printable character. It is possible for alphanumeric fields to contain non-printable characters, but the general assumption is that they won’t. For non-printable characters, use the b type field. See also a0 type fields.

b

0-255

Binary. Similar to the alphanumeric field type except that non-printable characters are now expected. This field type is generally used to store non-textual information.

i

1,2,3,4 or 8

Integer (signed). The ranges are as follows:

i1

-127 to 127

i2

-32767 to 32767

i3

-8,388,607 to 8,388,607

i4

-2,147,483,647 to 2,147,483,647

i8

-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

n

4 or 8

Number, with the number of decimal places to be stored assigned by the user, from 0 up to a maximum of 4. See number fields.

o

Object. Temporary fields only. This field type can be used to store the reference returned by an OLE object function. It has no explicit size as it is a pointer to another object. See object fields.

p

Pointer. Temporary fields only. This type has no explicit size as it takes its size and dimensions from the object pointed to. See pointer fields

r

4 or 8

Real. A floating point field stored internally in IEEE floating point format. The ranges are:

r4

Up to 6 significant digits; maximum absolute value approximately 3.4e+38

r8

10-37 - 10+38; up to 15 significant digits; maximum absolute value approximately 1.79e+308

t

1-255

User-defined. (For future use.)

u

1,2,3,4 or 8

Unsigned integer. The ranges are as follows:

u1

0 to 255

u2

0 to 65535

u3

0 to 16,777,215

u4

0 to 4,294,967,295

u8

0 to 18,446,744,073,709,551,615

Note that all arithmetic on u type fields is done at the 4-byte signed level. This can cause problems if u4 type fields are used. It is recommended that this type is used with extreme care.

The size of a field must be an appropriate one for the type. A field with an invalid type & size combination will be rejected, either by ddeditor or by the program compiler.

Regardless of the native data formats of the computer hardware on which it is running, Sculptor always stores data in its own, portable, format. Sculptor files may therefore be transported across different computer hardware architectures and operating systems.

Alphanumeric data is stored as ASCII text, with no byte swapping, and padded with trailing spaces. Integer numeric fields are stored as binary data, with the most significant bit at the lowest but one address; negative integers are held in two’s complement form with the lowest-address bit set. Floating point numeric fields are stored in IEEE standard double precision format with mantissa and exponent, the exponent being at the lowest address.


Number (n) type fields

Number (n) type fields have the format n4.d and n8.d. The user specifies in d precisely how many decimal places are to be stored, up to a maximum of four. For example:

n4.2

n8.3

The field is in 4-byte integer or 8-byte floating point. The actual data is stored as an integer, with the number of implied decimal places specified in d. This is very useful for the purpose of avoiding rounding errors.

If a field of type n8.3 is assigned the value #2.00/#3.00, the actual number stored is 666 (or 667, if rounding is being used), the .3 part of the type definition indicating the position of the decimal point. The field will display or print as 0.666. The standard temp sys.Rounding can be set to ON or OFF to determine whether rounding is to be used. The default is OFF.

When performing arithmetic with n type fields remember that no more than four decimal places can accumulate in such a field. This can have implications if they are used as intermediate storage during a calculation. In the following examples, “st.price” is an n8.4 type field:

  1. st.price = a * b
    st.price = st_price * 1.175
  2. st.price = (a * b) * 1.175

In (a), the result of (a * b) has been assigned to the n8.4 field “st.price” during the calculation, causing this to be rounded to four decimal places before the calculation is completed. This may cause a less accurate result.

The n type field provides a convenient method of handling monetary values, by use of the field types n4.2 and n8.2 (or n4.3 and n8.3 for currencies where the lower unit is measured in thousandths).


Object (o) type fields

This type may only be assigned to temporary fields. It is a pointer type, taking the type, size and dimensions of the object it refers to, and so is declared without these properties:

!temp field_id,,o

Object type fields are used to store references to objects, returned by the OLE object functions create_object(), get_object() and load_picture().

To destroy a reference in an o type temporary field, assign the value NULL to the field. If this was the last reference to the object, the object itself is destroyed and any memory that was being used by the object is freed.

If the temporary field is declared within a function, any reference stored in the field is deleted automatically when the function returns.


Pointer (p) type fields

This type may only be assigned to temporary fields. An object pointer field takes the type, size and dimensions of the object it refers to, and so is declared without these properties:

!temp pointer_id,,p

An object pointer points to the null object until it is assigned a reference. The null object is a pre-defined object, which has no type and always returns a null value if used in arithmetic. An object pointer cannot store data in this state.

Pointers may point to any object that bears an identifier. These include windows, functions, textboxes, fields, buttons, menus and menu items. Pointers enable common blocks of code to be created using pointer fields whose objects are assigned externally. Thus the common code may be run with the pointer referencing different objects.

In order to assign an object pointer to another object, use the following syntax:

pointer_id = &object_id

The object pointer may now be used as if it were the object pointed to. The following two statements are now identical:

read pointer_id nsr = label

read object_id nsr = label

Using pointer fields with arrays

A pointer field can itself be an array and can also point to an array field.

If a subscript is used with a pointer field that is not an array, the subscript value applies to the object to which the pointer refers. For example:

pointer_id = &field_id

then

pointer_id[2,5]

is equivalent to

field_id[2,5]

This example sets element 8 of the array pointed to to 496:

!temp Ptr,,p
!temp Field,,i2[12]

     Ptr = &Field
     Ptr[8] = 496

Note the difference between the following:

  1. pointer_id = &field_id

  2. pointer_id = field_id

In (a), the pointer is set to point at the field whose identifier is field_id.

In (b), the value of the field whose identifier is field_id is assigned to the object to which the pointer is currently pointing. If the pointer has not been assigned an object, this statement has no effect.

If a pointer is an array, then the subscript value applies to the pointer array. So:

pointer_id[4]

refers to the object pointed to by the 4th pointer in the pointer array.

If the object pointed to is also an array, the default element of that array is referenced, as shown in this example:

!temp Ptr,,p[5]
!temp Field,,i2[10]

     Ptr[3] = &Field  /* Set 3rd pointer in pointer array */
     setrow 5         /* Set default subscript for all single dimensioned arrays */
     Ptr[3] = 35      /* This allocates the value 35 to the default element of Field (Field[5]) */

Since Sculptor version 6.2.0 a pointer can be set to point to a specific element of an array, eg:

Ptr[3] = &Field[4]

Attention: this command was ignored and the pointer continued to point to whatever it pointed to before on any Sculptor version previous 6.2.0.

With the addition of nested records and record arrays, pointers can point to any subrecord and subscript:

!record Rec1[2] {
    !record SubRec[4] {
        fldArray,,i4[10]
    }
}
!temp ptr,,p

ptr =& Rec1[2].SubRec[3].fldArray[7]

ptr = 123          /* Equivalent to Rec1[2].SubRec[3].fldArray[7] = 123 */

A pointer may be reassigned to point to a new object. In order to change a pointer that is currently assigned to an object so that it points to no object, use the form:

pointer_id = &NULL

Since Sculptor version 6.2.0 is possible to have a runtime reference to access all the elements of a !record or !file pointed by a pointer, e.g:

!record DataRec[2] {
    !record SubRec[2] {
        num,,i4[2]
    }
}
!temp gblPtr,,p

gblPtr =& DataRec

gblPtr[2].SubRec[1].num[1] = 2111

NOTES

  • The isnull() function can be used to determine whether a specified pointer is currently pointing to anything.

  • A pointer can be used to specify a secondary index as the driving file for a report. See !drive.


The a0 type field

The special type a0 exists only for the purpose of displaying the field heading without a textbox in a screen form program. No box is created, but the heading appears on the screen to the left of the position where the box would have been. This provides a convenient way of displaying static textual information. The heading will not be affected by a clear or clearall command. The a0 type may exist in a file, but is more normally a temporary field.

The Static text window control is the recommended method of placing text on the screen.