Delphi 输出字符串不正确

Delphi 输出字符串不正确,delphi,Delphi,StrFormatByteSize要求arrsize为PWideChar 如何在Delphi 2009中正确显示结果?用WideChar数组替换Char数组,调用StrFormatByteSizeW。这在Delphi 2009中效果良好: procedure TForm1.Button1Click( Sender: TObject ); var arrSize: array[ 0..255 ] of Char; begin {same formating like in stat

StrFormatByteSize要求arrsize为PWideChar


如何在Delphi 2009中正确显示结果?

用WideChar数组替换Char数组,调用StrFormatByteSizeW。

这在Delphi 2009中效果良好:

procedure TForm1.Button1Click( Sender: TObject );
var
    arrSize: array[ 0..255 ] of Char;
begin
    {same formating like in statusbar of Explorer}
    StrFormatByteSize( 70846, arrSize, Length( arrSize ) * Sizeof( arrSize) );
    Label1.Caption := 'Result: ' + arrSize;
end;

您应该使用CodeSample来正确格式化代码。请将Buff声明为UnicodeString,以明确默认字符串类型在这种情况下是不合适的。此API需要Unicode字符串。不需要乘以SetLength中的SizeOfChar。第三个StrFormatByteSizeW参数可以指定为LengthBuff+1。@Rob:在上面发表我的评论后,我重新考虑了声明中的UnicodeString与String的关系;我同意,指定UnicodeString会使意图更加明确,因此会进行相应的编辑。谢谢你的更正。
procedure TForm1.Button1Click(Sender: TObject);
var
  Buff: UnicodeString;
  TheSize: Int64;
begin
  SetLength(Buff, 255);;
  TheSize := 1024768;
  StrFormatByteSizeW(TheSize, PWideChar(Buff), Length(Buff));
  Label1.Caption := Buff;
end;