二つのパスから相対パスを生成する

ふたつのパス、 例えば "C:\Program Files\Borland\Delphi5\lib\" をベースに "C:\Program Files\Common Files\Borland Shared\BDE\" への相対パス "..\..\..\Common Files\Borland Shared\BDE\" を求めるには ExtractRelativePath 関数を使います。第一引数にはベースとなるパス、第二引数に参照先パスを記述します。

■ ExtractRelativePathの使用例
procedure TForm1.Button1Click(Sender: TObject);
var
  Path1 : string;
  Path2 : string;
begin
  Path1 :=  'C:\Program Files\Borland\Delphi5\lib\';
  Path2 :=  'C:\Program Files\Common Files\Borland Shared\BDE\';  
  //結果は ..\..\..\Common Files\Borland Shared\BDE\
  Label1.Caption  :=  ExtractRelativePath(Path1, Path2);
end;

逆は ExpandFileName 関数を使います。