将一个相对于基本路径的相对路径转化为绝对路径


Delphi中没有提供将一个相对于基本路径的相对路径转化为绝对路径的函数,我迫不得已自己写了一个。

function GetAbsolutePath(BasePath, RelativePath:string):string;

implementation
uses ComObj, ComConst, dialogs;

function PathCombine(lpszDest: PChar; const lpszDir, lpszFile: PChar):
PChar; stdcall; external 'shlwapi.dll' name 'PathCombineA';
function PathCombineA(lpszDest: PAnsiChar; const lpszDir, lpszFile:
PAnsiChar): PAnsiChar; stdcall; external 'shlwapi.dll';
function PathCombineW(lpszDest: PWideChar; const lpszDir, lpszFile:
PWideChar): PWideChar; stdcall; external 'shlwapi.dll';

function GetAbsolutePath(BasePath, RelativePath:string):string;
var
Dest:array [0..MAX_PATH] of char;
begin
FillChar(Dest,MAX_PATH+1,0);
PathCombine(Dest,PChar(BasePath), PChar(RelativePath));
Result:=string(Dest);
end;