Delphi - 在 assignfile() 中使用字符串变量的名称

Delphi - Use a string variable's name in assignfile()

是否可以在 assignfile 命令中使用变量?

例如

f : Textfile ;
sFile : string ;  {contains 'MyFile.txt' as content}

...

cFileDir = 'C:\Users\User\Desktop\Data Engine\Data\Country' ;

...

Assignfile(f, cFileDir + '\' + sFile) ;

...

非常感谢你的帮助。如果不清楚,我会编辑问题以添加更多详细信息。

Is it possible to use a variable in the AssignFile command?

是的。

  1. AssignFile 的第二个参数的类型为 string
  2. 表达式 cFileDir + '\' + sFile 的类型为 string

FWIW,AssignFile 被称为 函数 而不是 命令 。像这样掌握术语将帮助您更有效地学习这门语言。