FastReport Format函数unicode错误
FastReport Format function unicode error
我在 Delphi 10.2 上使用 fastreport 5.4.6,但在使用 unicode args 显示 Format 函数时 fastreport 出错。这是错误
使用文本创建备忘录 = [格式('%s' , ['nghìn tỷ'])] nghìn tỷ
会显示"nghìn t? nghìn tỷ"
如何解决。请帮助我。
编辑
我在 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;
更改后
[Format('%s' , ['một nghìn tỷ'])]
会显示"một nghìn tỷ"。我不知道如果我改变功能会发生什么(我是 delphi 的新手)
已修复。 FR 5.6.2 工作正常。
fs_isysrtti.pas 来自 5.6.2:
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;
fs_itools.pas 来自 5.6.2:
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;
我在 Delphi 10.2 上使用 fastreport 5.4.6,但在使用 unicode args 显示 Format 函数时 fastreport 出错。这是错误
使用文本创建备忘录 = [格式('%s' , ['nghìn tỷ'])] nghìn tỷ
会显示"nghìn t? nghìn tỷ"
如何解决。请帮助我。
编辑 我在 fastreport
的 fs_itools.pas 中更改函数 VariantToVarRecprocedure 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;
更改后
[Format('%s' , ['một nghìn tỷ'])]
会显示"một nghìn tỷ"。我不知道如果我改变功能会发生什么(我是 delphi 的新手)
已修复。 FR 5.6.2 工作正常。 fs_isysrtti.pas 来自 5.6.2:
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;
fs_itools.pas 来自 5.6.2:
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;