SmartPascal
FillChar
Procedure
Fills out a section of storage with a fill character or byte value System unit
 procedure FillChar ( var Buffer; FillCount : Integer; FillValue : Byte ) ;
Description
The FillChar procedure fills out a section of storage Buffer with the same byte or character FillValue FillCount times.
 
It is principally used to initialise arrays of numbers. It can be used to initialise records and strings, but care should be used to avoid overwriting length fields. StringOfChar is best for filling out strings to the same character.
Related commands
GetMem Get a specified number of storage bytes
SetString Copies characters from a buffer into a string
StringOfChar Creates a string with one character repeated many times
 
Example code : Fill out a word array
var
  data : array[0..3] of Word;
  i : Integer;

begin
  // Fill out the Word array
  ShowMessage('Before FillChar :');
  for i := 0 to 3 do
  begin
    data[i] := i*5;
    ShowMessage(IntToStr(i)+' element value = '+IntToStr(data[i]));
  end;

  // Now fill out the array with the value 1
  // A Word is 2 bytes : 00000001 00000001 hex = 257 decimal
  FillChar(data, 4*SizeOf(Word), 1);

  // And show the array now
  ShowMessage('After FillChar :');
  for i := 0 to 3 do
    ShowMessage(IntToStr(i)+' element value = '+IntToStr(data[i]));
end;
Show full unit code
   Before FillChar :
   0 element value = 0
   1 element value = 5
   2 element value = 10
   3 element value = 15
   After FillChar :
   0 element value = 257
   1 element value = 257
   2 element value = 257
   3 element value = 257