title: Return the root directory of Delphi executable
body: <p>I have a Delphi application executing and when I call <code>GetCurrentDir</code> the following  returns:</p>
  
  <blockquote>
    <p>C:\dev\w32\2015\BCSLBDemo\Win32\Debug</p>
  </blockquote>
  
  <p>When I call <code>ExtractFileDir(GetCurrentDir())</code> I receive the following:</p>
  
  <blockquote>
    <p>C:\dev\w32\2015\BCSLBDemo\Win32</p>
  </blockquote>
  
  <p>What I desire is <code>C:\dev\w32\2015\BCSLBDemo</code></p>
  
  <pre><code>function RetRoot: string;
  var
    i: Integer;
    buf: string;
  begin
    Result := '';
    buf := ExtractFileDir(GetCurrentDir());
    i := Length(buf);
    repeat
      dec(i);
    until (buf[i] = '\') or (i &lt; 3);
    if buf[i] = '\' then
    begin
      Delete(buf, i, Length(buf));
      Result := buf;
    end;
  end;
  </code></pre>
  
  <p>I wrote this function to get the desired result.  I would like to know if there is a better approach to accomplish retrieving the root directory of a Delphi executable.</p>