简体   繁体   中英

Read a file in Delphi program from a folder where the program is installed to by Inno Setup

I would like to make an install program (using Inno Setup) for a desktop application I wrote using Delphi community edition. The code contains statements that open a text file on my C drive:

var
  filename: string;
begin
  filename := 'C:\Program Files (x86)\Text_for_BC.txt';
  StringList1 := TStringList.Create;
  StringList1.LoadFromFile(fileName); 

The program runs fine so long as the .exe and the text file live on my computer. However, were I to try and share the program with a friend by building an install program with Inno Setup, the above code would prevent a successful installation since the path for the textfile (the path that Inno Setup asks me to supply) does not exist on a computer other than my own.

How should I have written the code above to avoid the 'file not found' error?

Deploy both files to the same directory in Inno Setup.

And have your program load the file from its own directory:

filename := ExtractFilePath(ParamStr(0)) + 'Text_for_BC.txt'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM