Delphi中来自服务应用程序的给定文件的相对路径

Del*_*mer 2 delphi windows-services path relative-path

我在加载文件时遇到问题,因为我正在传递函数的相对路径FileExists(Filename: String)并且它返回false,也就是说,它在我传递的目录中找不到该文件.

我有一个Template.htmlD:\Programming\Delphi\Projects\SendMail目录中命名的文件,以及一个用Delphi编写的服务,它.EXE位于D:\Programming\Delphi\Automation目录中.我正在传递相对路径:.\..\Projects\SendMail\Template.htmlto FileExists(),但它返回该文件不存在.

我认为这与服务的相对路径和应用程序的相对路径不同有关.任何人都可以帮我吗?

The*_*Fox 8

正如lorenzog所说,尝试指定完整路径.

您也可以尝试将currentdir设置为您的喜好.

//sets currentdir to your application.exe dir
SetCurrentDir(ExtractFileDir(ParamStr(0))); 
Run Code Online (Sandbox Code Playgroud)