Fixed: conversion errors now report the named specifier causing the error
This commit is contained in:
parent
4cab1f15b4
commit
8c2549eda0
@ -106,6 +106,7 @@ var
|
|||||||
paramNames: TStringList;
|
paramNames: TStringList;
|
||||||
paramValues: array of TVarRec;
|
paramValues: array of TVarRec;
|
||||||
specifierIndex: Integer;
|
specifierIndex: Integer;
|
||||||
|
errorMsg: String;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if Length(AParams) mod 2 = 1 then
|
if Length(AParams) mod 2 = 1 then
|
||||||
@ -192,11 +193,27 @@ begin
|
|||||||
|
|
||||||
Inc(paramIndex);
|
Inc(paramIndex);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
try
|
||||||
|
Result := Format(formatString, paramValues);
|
||||||
|
except
|
||||||
|
on E:EConvertError do
|
||||||
|
begin
|
||||||
|
errorMsg := E.Message;
|
||||||
|
|
||||||
|
{ Translate specifiers in error messages back to names }
|
||||||
|
for paramIndex := 0 to Pred(paramNames.Count) do
|
||||||
|
errorMsg := StringReplace(errorMsg, SpecifierChar + IntToStr(paramIndex) + ':',
|
||||||
|
SpecifierChar + SpecifierNameStart +
|
||||||
|
paramNames[paramIndex] + SpecifierNameEnd + ':',
|
||||||
|
[rfReplaceAll]);
|
||||||
|
|
||||||
|
raise EConvertError.Create(errorMsg);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
finally
|
finally
|
||||||
FreeAndNil(paramNames);
|
FreeAndNil(paramNames);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Result := Format(formatString, paramValues);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user