【问题标题】:Read text file line by line in Inno Setup在 Inno Setup 中逐行读取文本文件
【发布时间】:2022-06-22 22:05:29
【问题描述】:

我正在尝试使用 Inno Setup 逐行读取文本文件。

我试过这里提到的这个:https://jrsoftware.org/ispphelp/index.php?topic=fileread

function ShowLines(): Boolean;
var
  list: Integer;
begin
  list := FileOpen(ExpandConstant('{tmp}\file.txt'));

  if !FileEof(list) then begin
    try
      repeat
         MsgBox(FileRead(list), mbInformation, MB_OK);
      until !FileEof(list);
    finally
      FileClose(list);
    end;
  end;
  Result := True;
end;

但它会在FileOpen(可能在其他文件函数上)给出错误,它是一个未知的标识符。问题出在哪里?

文件小于 50kb。

【问题讨论】:

    标签: inno-setup pascalscript


    【解决方案1】:

    您尝试从 Pascal 脚本调用的所有函数实际上都是 preprocessor functions。 Pascal 脚本没有可以逐行(或任何类型的块)读取文件的内置函数。

    您可以使用 WinAPI 文件函数来实现它,例如 CreateFileReadFile

    但如果文件不是太大,你可以简单地使用内置函数LoadStringsFromFile。示例见Read strings from file and give option to choose installation

    类似问题:"Unknown Identifier 'FileOpen'" when trying to detect locked file in Inno Setup code


    看到您正在从{tmp} 读取文件,很可能您实际上正在读取从安装程序本身提取的临时文件。如果是这种情况,则意味着您已经在编译时拥有该文件。在这种情况下,您确实可以使用预处理器函数在编译时读取文件。

    但这需要使用完全不同的语言/语法的代码。一些例子:

    【讨论】:

      猜你喜欢
      • 2017-02-12
      • 1970-01-01
      • 2014-12-01
      • 2015-10-25
      • 2011-07-23
      • 2012-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多