[英]Error: No overloaded versoin of 'IntToStr'
When compiling the following code: 编译以下代码时:
procedure TMainWin.FormActivate(Sender: TObject);
var LineRaw : String;
LinesFile : TextFile;
i, i2 : integer;
tempChar : String;
CurTempCharPos : integer;
begin
AssignFile(LinesFile, 'Lines.txt');
Reset(LinesFile);
i := 0;
tempChar := '';
CurTempCharPos := 1;
while not EoF(LinesFile) do begin
i := i+1; //ticker
ReadLn(LinesFile, LineRaw);
for i2 := 0 to 4 do begin
tempChar := LineRaw[CurTempCharPos] + LineRaw[CurTempCharPos +1];
Lines[i,i2] := IntToStr(tempChar);
tempChar := '';
CurTempCharPos := CurTempCharPos + 3;
end;
end;
CloseFile(LinesFile);
end;
With Lines being defined in another form: 使用以另一种形式定义的线:
unit uGlobal;
interface
type
aLines = array[1..5] of integer;
aLinesFinal = array of aLines;
var
Lines : aLinesFinal;
implementation
end.
I get the following error: There is no overloaded version of 'IntToStr' that can be called with these arguments. 我收到以下错误:没有可用这些参数调用的'IntToStr'重载版本。 The error points to the line:
错误指向该行:
Lines[i,i2] := IntToStr(tempChar);
Here is the declaration of tempChar
: 这是
tempChar
的声明:
tempChar : String;
It is a string. 它是一个字符串。 And here is the call that the compiler rejects:
这是编译器拒绝的调用:
Lines[i,i2] := IntToStr(tempChar);
The IntToStr
function, which has various overloads, accepts integer input parameters and returns strings. IntToStr
函数具有各种重载,它接受整数输入参数并返回字符串。 You cannot pass a string to IntToStr
. 您不能将字符串传递给
IntToStr
。 Perhaps you meant to write: 也许您打算写:
Lines[i,i2] := StrToInt(tempChar);
Some other comments: 其他一些评论:
Lines
. Lines
。 This means that whilst the code might compile, it will fail at runtime. aLines
as array[1..5] of integer
, the valid values for i2
are 1
to 5
inclusive. aLines
声明为aLines
array[1..5] of integer
,因此i2
的有效值为1
到5
含)。 You use 0
to 4
inclusive. 0
到4
含0
和4
。 Again, that's going to bite at runtime. tempChar
is a poor name for something that can hold more than a single character. tempChar
是一个不好的名字,因为它可以容纳多个字符。 OnActivate
seems to be an unusual place to execute this code. OnActivate
似乎是执行此代码的不寻常地方。 This event will run multiple times.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.