【问题标题】:What is Free Pascal Error 3208 Illegal assignment to for-loop variable [closed]什么是 Free Pascal Error 3208 Illegal assignment to for-loop variable [关闭]
【发布时间】:2021-03-22 09:48:12
【问题描述】:

告诉我有关 Free Pascal 编译器错误 3208“对 for 循环变量的非法赋值”。

【问题讨论】:

  • 您写的要自己回答的问题必须符合与任何其他问题相同的质量准则。这一个缺乏任何细节。它至少应包含导致显示此错误的代码。
  • 其实取决于模式。在 $mode TP 中,允许分配循环变量,就像在 TP 中一样。因此我投票决定重新开放。

标签: freepascal conditional-compilation for-in-loop compiler-directives


【解决方案1】:

我们无法在 For-In 循环中更改索引器变量的值。

为了演示,将此代码复制到一个简单程序类型的新项目中,然后编译它。然后,将'$'字符添加到第一行的“Define symDemo”注释中,将其转换为编译器指令,并尝试编译。

讨论见https://forum.lazarus.freepascal.org/index.php?topic=17488.0

program ForIn; {$AppType Console} { Define symDemo}
var
  strChrLst              , // list of  characters, without separators
  idxChrOne : string     ; // only one character; indexer in For-In loop
  strChrUpr : string = ''; // uppercase version of the current character, init-ed to empty
begin
  strChrLst := 'a[z'                            ; // initialize list of characters to work on
  for idxChrOne in strChrLst do begin           ; // scan all characters in the list
    {$IfNDef symDemo}                           ; // when "symDemo" is not defined
    strChrUpr := UpCase( idxChrOne )            ; // convert the current character to upcase
    {$Else}                                     ; // when "symDemo" is     defined
    idxChrOne := UpCase( idxChrOne )            ; // gives Error 3208 on "idxChrOne"
    {$EndIf}                                    ; // done with "symDemo"
    if ( strChrUpr < 'A' )                        // when the current character is
    Or ( strChrUpr > 'Z' ) then begin           ; //    outside the range of alphabet letters
      writeln(StdErr,'Not a letter: ',idxChrOne); // emit the non-letter character on StdErr
    end                                         ; // done with the non-letter character
  end                                           ; // done scanning characters in the list
end.

【讨论】:

    猜你喜欢
    • 2022-09-23
    • 2021-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多