FillChar Procedure
FillChar
fills a variable with
Count
bytes, copying Fill
as
many times as needed. Fill
can be a
Byte
-sized ordinal value.
FillChar
is not a real
procedure.
Note that Buffer
is not a pointer. Do not pass the
address of a variable, but pass the variable itself. If you
dynamically allocate memory, be sure to dereference the pointer when
calling FillChar
.
If the ordinal value of the Fill
argument is out
of the range of a Byte
, Delphi silently uses only
the least significant byte as the fill byte. Delphi does not report
an error, even if you have overflow checking enabled.
The most common use for FillChar
is to fill a
buffer with zeros. You can also call the
SysUtils.AllocMem
function, which calls
GetMem
and then FillChar
to
fill the newly allocated memory with all zeros.
When allocating a new record or array that contains long strings,
dynamic arrays, interfaces, or Variant
s, you must
initialize those elements. The Initialize
procedure is usually the best way to do this, but it does not
initialize any other elements of the array or record. Instead, you
can call FillChar
to fill the new memory with all
zeros, which is a correct initial value for strings, dynamic arrays,
interfaces, and Variant
s. When you free the
record, be sure to call Finalize
to free the
memory associated with the strings, dynamic arrays, interfaces, and
Variant
s.
If Count
< 0, FillChar
does
nothing.