Name
FillChar Procedure
Syntax
procedure FillChar(var Buffer; Count: Integer; const Fill);
Description
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.
Tips and Tricks
Note that
Bufferis 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 callingFillChar.If the ordinal value of the
Fillargument is out of the range of aByte, 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
FillCharis to fill a buffer with zeros. You can also call theSysUtils.AllocMemfunction, which callsGetMemand thenFillCharto fill the newly allocated memory with all zeros.When allocating a new record or array that contains long strings, dynamic arrays, interfaces, or
Variants, you must initialize those elements. TheInitializeprocedure is usually the best way to do this, but it does not initialize any other elements of the array or record. Instead, you can callFillCharto fill the new memory with all zeros, which is a correct initial value for strings, dynamic arrays, interfaces, andVariants. When you free the record, be sure to callFinalizeto free the memory associated with the strings, dynamic arrays, interfaces, andVariants.If
Count< 0,FillChardoes nothing.
Example ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access