代码实例 var hModule : THandle; buff: array[0..MAX_PATH] of Char; begin dwSize := MAX_PATH; hModule := GetModuleHandle(nil); GetModuleFileName(hModule, buff, dwSize); showmessage(ExtractFilePath(StrPas(buff)); end;
ExtractFilePath(ParamStr(0)) 很简单
送你一个小函数Function LocalPath():string; begin result:=extractfilepath(paramstr(0)); end;
ExtractFilePath(Application.ExeName);
function GetExePath():string;//取应用程序路径 var ExePath:string; iPos,Index:integer; begin ExePath:=Application.ExeName; iPos := 0; for Index := 1 to Length(ExePath) do if ExePath[Index] = '\' then iPos := Index; Result := copy(ExePath,1,iPos - 1); end;
GetModuleName可以得到程序的全路径+文件名
然后再用ExtractFilePath函数得到路径
var
hModule : THandle;
buff: array[0..MAX_PATH] of Char;
begin
dwSize := MAX_PATH;
hModule := GetModuleHandle(nil);
GetModuleFileName(hModule, buff, dwSize);
showmessage(ExtractFilePath(StrPas(buff));
end;
很简单
begin
result:=extractfilepath(paramstr(0));
end;
var
ExePath:string;
iPos,Index:integer;
begin
ExePath:=Application.ExeName;
iPos := 0;
for Index := 1 to Length(ExePath) do
if ExePath[Index] = '\' then
iPos := Index;
Result := copy(ExePath,1,iPos - 1);
end;