Fills out a section of storage with a fill character or byte value System unit
 procedure FillChar ( var Buffer; FillCount : Integer; FillValue : Byte ) ;
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
 Author links

 Buy Website Traffic at

 Buy Proxies at
 Download this web site as a Windows program.

Example code : Fill out a word array
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
unit Unit1;
  // The System unit does not need to be defined
  Forms, Dialogs;
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
Form1: TForm1;
{$R *.dfm} // Include form definitions
procedure TForm1.FormCreate(Sender: TObject);

  data : array[0..3] of Word;
  i : Integer;

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

  // 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]));
Hide 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
Delphi Programming Neil Moffatt 2002 - 2018. All rights reserved.  |  Home Page