3.2. Copying data


fillchar is a Pascal function that allows you to fill any data structure with a particular byte. Although it would appear to only be useful for arrays of bytes, a little knowledge of the storage format of other structures can make it a lot more useful.

Many data types can be zeroed by using fillchar with an argument of 0. This includes all integer and floating point types as well as the set type (makes it the empty set), and will set boolean variables to false. A value of 255 (0xff) will set signed integer data types to -1, and unsigned integer data types to their largest possible value. A value of 127 (0x7f) will set signed integer data types to a value close to their largest value.

In many cases, these operations could be done with a for loop. The reasons for using fillchar are that it is quicker to write and it is quite optimised.


A similar function to fillchar is move. This allows a chunk of data to be copied from one memory location to another. It is more flexible than the assignment operator because you don't have to copy complete data structures; you can select any region of memory you like. This makes it quite handy when using dynamic arrays.

[Prev] [Next] [Up]

Last updated Sun Nov 28 22:04:38.0000000000 2004. Copyright Bruce Merry (bmerry '@' gmail dot. com).