我在Delphi 10.2上使用fastreport 5.4.6但是当使用unicode args显示Format函数时fastreport有错误。这是错误
创建带文字的备忘录= [格式('%s',['nghìntỷ'])]nghìntỷ
它会显示“nghìnt?nghìntỷ”
如何修复它。请帮帮我。
修改 我在fastreport的fs_itools.pas中更改函数VariantToVarRec
procedure VariantToVarRec(v: Variant; var ar: TVarRecArray);
var
...
varOleStr, varString:
begin
// ar[i].VType := vtString;
// New(ar[i].VString);
//{$IFDEF Delphi12}
// ar[i].VString^ := AnsiString(v[i]);
//{$ELSE}
// ar[i].VString^ := v[i];
//{$ENDIF}
ar[i].VType := vtUnicodeString;
ar[i].VString := pointer(UnicodeString(v[i]));
end;
{$IFDEF Delphi12}
varUString:
begin
ar[i].VType := vtUnicodeString;
New(ar[i].VUnicodeString);
PUnicodeString(ar[i].VUnicodeString)^ := v[i];
end;
{$ENDIF}
...
end;
更改后
[格式('%s',['mộtnghìntỷ'])]
将显示“mộtnghìntỷ”。我不知道如果我改变功能会发生什么(我是delphi的新手)
答案 0 :(得分:1)
固定。 FR 5.6.2工作正常。 来自5.6.2的fs_isysrtti.pas:
function FormatV(const Fmt: String; Args: Variant): String;
var
ar: TVarRecArray;
sPtrList: TList;
begin
VariantToVarRec(Args, ar, sPtrList);
Result := Format(Fmt, ar);
ClearVarRec(ar, sPtrList);
end;
来自5.6.2的fs_itools.pas:
procedure VariantToVarRec(v: Variant; var ar: TVarRecArray; var sPtrList: Tlist);
procedure ClearVarRec(var ar: TVarRecArray; var sPtrList: TList);
...
procedure VariantToVarRec(v: Variant; var ar: TVarRecArray; var sPtrList: TList);
var
i: Integer;
{$IFDEF Delphi12}
pWStr: PWideString;
{$ELSE}
pAStr: PAnsiString;
{$ENDIF}
begin
SetLength(ar, VarArrayHighBound(v, 1) + 1);
sPtrList := TList.Create;
for i := 0 to VarArrayHighBound(v, 1) do
...
varString:
begin
ar[i].VType := vtString;
New(ar[i].VString);
{$IFDEF Delphi12}
ar[i].VString^ := AnsiString(v[i]);
{$ELSE}
ar[i].VString^ := v[i];
{$ENDIF}
end;
varOleStr:
begin
{$IFDEF Delphi12}
ar[i].VType := vtWideString;
New(pWStr);
sPtrList.Add(pWStr);
pWStr^ := WideString(v[i]);
ar[i].VWideString := PWideString(pWStr^);
{$ELSE}
ar[i].VType := vtAnsiString;
//New(ar[i].VAnsiString);
New(pAStr);
sPtrList.Add(pAStr);
pAStr^ := AnsiString(v[i]);
ar[i].VAnsiString := PAnsiString(pAStr^);
{$ENDIF}
end;
{$IFDEF Delphi12}
varUString:
begin
ar[i].VType := vtUnicodeString;
New(ar[i].VUnicodeString);
PUnicodeString(ar[i].VUnicodeString)^ := v[i];
end;
{$ENDIF}
varVariant:
begin
ar[i].VType := vtVariant;
New(ar[i].VVariant);
ar[i].VVariant^ := v[i];
end;
end;
...
procedure ClearVarRec(var ar: TVarRecArray; var sPtrList: TList);
var
i: Integer;
begin
for i := 0 to Length(ar) - 1 do
if ar[i].VType in [vtExtended, vtString, vtVariant {$IFDEF Delphi6}, vtInt64 {$ENDIF}] then
Dispose(ar[i].VExtended);
for i := 0 to sPtrList.Count - 1 do
Dispose(sPtrList[i]);
sPtrList.Free;
Finalize(ar);
end;