用什么方法可以得到运行程序自己的完整路径.(100分)

  • 主题发起人 主题发起人 数字化强盗
  • 开始时间 开始时间

数字化强盗

Unregistered / Unconfirmed
GUEST, unregistred user!
用什么方法可以得到运行程序自己的完整路径.是即时的得到.即使被换过了目录.在下<br>次运行时又能得到.比如每次运行把自己的路径添入注册表,
 
用GetCurrentDirectory()<br><br>The GetCurrentDirectory function retrieves the current directory for the current process. <br><br>DWORD GetCurrentDirectory(<br><br>&nbsp; &nbsp; DWORD nBufferLength, // size, in characters, of directory buffer <br>&nbsp; &nbsp; LPTSTR lpBuffer // address of buffer for current directory <br>&nbsp; &nbsp;); <br>&nbsp;<br><br>Parameters<br><br>nBufferLength<br><br>Specifies the length, in characters, of the buffer for the current directory string. The buffer length must include room for a terminating null character. <br><br>lpBuffer<br><br>Points to the buffer for the current directory string. This null-terminated string specifies the absolute path to the current directory. <br><br>&nbsp;<br><br>Return Values<br><br>If the function succeeds, the return value specifies the number of characters written to the buffer, not including the terminating null character. <br>If the function fails, the return value is zero. To get extended error information, call GetLastError. <br>If the buffer pointed to by lpBuffer is not large enough, the return value specifies the required size of the buffer, including the number of bytes necessary for a terminating null character.
 
Application.Exename<br>ParamStr(0)
 
ExtractFilePath<br><br>我就不把帮助贴上来了
 
:-)<br><br>application.exename<br><br>This property include full path.
 
extractfilepath(application.ExeName);<br><br>这样就可反回当前应用程序的完整路径,<br>不论你如何换,一定是当前的。<br>最后跟着个"/"号的。
 
function ExtractFilePath(const FileName: string): string;<br>这是它的用法.<br>用application.Exename是最好的方法.也很简单
 
Uses<br>&nbsp; &nbsp; SysUtils;<br><br>........<br>path:=ExtractFilePath(Application.ExeName);<br>........
 
ParamStr(0)最准确
 
var <br>&nbsp; StartPath:String;<br>在OnCreate事件中<br>&nbsp;StartPath=GetCurrentDir;<br>&nbsp;if StartPath&gt;3 then <br>&nbsp; &nbsp;StartPath:=StartPath+'/'<br>&nbsp;
 
Reg.Writestring(ExtractFilePath(Application.Exename));<br>这句出错<br>Not enough actual perameters<br>是那儿不对?
 
没写键值得名字
 
writestring有两个参数一个是键一个是值<br>如Reg.Writestring("ExePath",ExtractFilePath(Application.Exename));<br>会在注册表的当前路径中写一个ExePath的键,其值为你的程序路径
 
很遗憾,我昨天回答过这个问题,但是帖子不是 数字化强盗 的。<br><br>Reg.Writestring要求两个参数,键值和键名,你的参数不够。<br>再说这个和你的问题没有任何关系。<br>有空去看看这个帖子。<br>&lt;a href="./DispQ.asp?LID=473716"&gt;Reg.Writestring(extractfilepath(exe));这句话怎么写?100(100分) &lt;/a&gt;<br>再一次为你的行为遗憾
 
多人接受答案了。
 
这样子分分要不得,前面的人很多人都很热心的讨论了你的问题,而且说得都很切题你不给分,<br>两个过路的人却把分分了,这样子对别人不住的
 
后退
顶部