Delphi 7 if it matters.

procedure writeLog ( varName, varValue: string );
var
  length, i :Integer;
begin
  Append( logFile );
  ShowMessage (varName);
  For i := Length(varName) to 20 do       //line 37
  begin
     varName := varName + ' ';
  end;
  WriteLn( logFile, varName + ': ' + varValue );
  CloseFile( logFile );
end;

I get the error:

[Error] felirat.dpr(37): Missing operator or semicolon

All the semicolons seem just fine to me. What am I missing?

有帮助吗?

解决方案

You declared a local variable named length. This local variable hides the function of the same name declared in the System unit (Delphi, as a Pascal derivative, is case-insensitive). So when you wrote:

For i := Length(varName) to 20 do      

the compiler sees Length as the variable rather than the function. And that leads to your compiler error.

Possible solutions:

  • Use a different name for the variable, e.g. len.
  • Use the fully scoped name for the function: System.Length().
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top