简体   繁体   English

错误:“ IntToStr”的游标没有重载

[英]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: 其他一些评论:

  • I doesn't look like you initialised Lines . 我看起来不像您初始化Lines This means that whilst the code might compile, it will fail at runtime. 这意味着尽管代码可以编译,但在运行时将失败。
  • Since you declared 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的有效值为15含)。 You use 0 to 4 inclusive. 您使用0404 Again, that's going to bite at runtime. 再次,这将在运行时咬伤。
  • You really should enable range checking as a matter of urgency, since when you start executing this code that setting will reveal the errors above, and no doubt more besides. 您确实应该紧急地启用范围检查,因为当您开始执行此代码时,该设置将揭示上面的错误,并且毫无疑问会更多。
  • In my view tempChar is a poor name for something that can hold more than a single character. 在我看来, tempChar是一个不好的名字,因为它可以容纳多个字符。
  • As @TLama points out, OnActivate seems to be an unusual place to execute this code. 正如@TLama指出的那样, OnActivate似乎是执行此代码的不寻常地方。 This event will run multiple times. 此事件将运行多次。 Perhaps you should be executing this code at start up. 也许您应该在启动时执行此代码。 In any case, code like this should not be in an event handler and should be moved to a separate method which an event handler can call. 无论如何,这样的代码都不应放在事件处理程序中,而应移到事件处理程序可以调用的单独方法中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM