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

518 views Asked by At

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

Eg.

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

...

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

...

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

...

I appreciate your help very much. if it's unclear I'll edit the question to add more details.

1

There are 1 answers

1
David Heffernan On BEST ANSWER

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

Yes.

  1. The second parameter of AssignFile has type string.
  2. The expression cFileDir + '\' + sFile has type string.

FWIW, AssignFile is known as a function rather than a command. Getting on top of terminology like this will help you learn the language more effectively.