5

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.

1 Answer 1

10

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.