i use delphi 2010. i need to fill the char array with spaces not nulls. i used following code which doesn't work.
procedure TForm1.FormCreate(Sender: TObject);
var
aCharArray: array[0..9] of Char;
begin
FillChar(aCharArray, sizeof(aCharArray), #32); // doesn't work
FillChar(aCharArray, sizeof(aCharArray), ' '); // doesn't work
Caption := aCharArray;
end;
the caption is printed with strange crosses. in an array of ansichar it works well.
please let me know the reason and the solution.
thanks.
FillChar
is mis-named in Unicode Delphi. It should really be named FillAnsiChar
. So you are filling the string with UTF-16 characters having ordinal value $2020
, aka U+2020 (DAGGER), †.
Instead you should use StringOfChar
:
Caption := StringOfChar(' ', 10);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With