This is a little different from SameText
question.
I need to convert AnsiString
into an Integer
.
var
param: AnsiString;
num: Integer;
begin
if TryStrToInt(param, num) then
...
In pre-Unicode Delphi I would use TryStrToInt
function, but in modern Delphi there is only Unicode version of it, so I'm getting this warning: W1057 Implicit string cast from 'AnsiString' to 'string' upon call.
My question is, how to properly convert AnsiStrings in modern Delphi without getting compiler warnings (and without superfluously having to cast string to UnicodeString(text))
UnicodeString
in your code. Standard practise is to use its alias,string
. Not that the declaration ofTryStrToInt
usesstring
rather thanUnicodeString
. So the explicit cast should bestring(param)
. – David Heffernan