See Also: Declaring Variables, Variable Declaration Commands, Struct, Char


Declares one or more UChar (one byte unsigned integer) variables. Arrays of UChar can be used to read and write entire files.


To declare UChar variables

UChar {identifier} [… {identifier}]


To declare array variables of type UChar

UChar{dimension-list} {identifier} […{identifier}]


What It Does

The UChar command declares 1 byte unsigned integer variables in the range 0 to 255.

Multiple variables may be declared on one command line, with their names separated from each other by spaces.

UChar arrays are useful for storing binary data and reading and writing from and to whole files.


Procedure DoTest

    UChar ucMyVar


    Move 1 To ucMyVar


This example declares a UChar variable named ucMyVar and initializes its value to 1.

UChar[] ucBoatLength

This example declares 1 dynamic array variable, named ucBoatLength, containing an undefined number of elements of type UChar.

UChar[5] ucBoatLength

This example declares 1 static array variable, named ucBoatLength, containing 5 of elements of type UChar.

UChar[][3] ucBoatLength

This example creates a two-dimensional dynamic array variable named ucBoatLength, containing an undefined number of elements of type UChar. Conceptually, this represents a rectangular array with an undefined number of rows, each of 3 columns.

You can declare dynamic multi-dimensional arrays where all dimensions are dynamic; these are called jagged arrays.


Working with UChar Arrays

An unsigned char (UChar) is a byte. An array of UChar (UChar[]) is therefore an array of bytes. In applications, arrays of bytes can be used to represent (single byte) character data or binary data.

In DataFlex, Strings are normally used to represent character data and Strings or a memory heap is used to represent binary data. With strings used for binary data, you have to be very careful about embedded nulls. With memory, you have to allocate and deallocate the memory yourself and then work with low level memory commands.

An alternate to these approaches is to use UChar arrays. You can do so using the following:

This should greatly reduce the need to use memory for these tasks. However, interaction between a memory heap and a UChar array is easily handled by using AddressOf() with a UChar array variable (e.g., Move (AddressOf(MyUCharVar)) to pValue). This will point to the first byte of the UChar array. The length of that array is, of course, SizeOfArray().

It should also be noted that UChar array variables can be stored as properties with no size limitation or concern for embedded zeros.

The advantages of this are: