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 |
// 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; interface uses // The System unit does not need to be defined SysUtils, Forms, Dialogs; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} // Include form definitions procedure TForm1.FormCreate(Sender: TObject); 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; end.
|
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
|
|