title: Changing the directory of Delphi OpenDialog
body: <p>A little background of the program:<br>
  The program uses a tabbed interface to work on multiple files at the same time.<br>
  I'm trying to change the directory of the OpenDialog so every time I call open a file will show the directory of the file I am working on currently, but even when I set <code>InitialDir</code> to the file's path it always displays the last opened file directory, not the one I am setting it to.<br>
  I tried the following:</p>
  
  <pre><code>if Length(CurrentFileName) &gt; 0 then
  begin
    OpenFileDialog.InitialDir :='';
    SetCurrentDirectory(PChar(CurrentFileName));
    OpenFileDialog.InitialDir := ExtractFileDir(CurrentFileName);
  end;
  if OpenFileDialog.Execute then
  ...
  </code></pre>
  
  <p>Where <code>CurrentFileName</code> is the full path with the filename of the current tab's opened file. But no luck.</p>
  
  <p>Is there any way to achieve this?</p>
  
  <p>So for example:</p>
  
  <p><code>tab1</code> has <code>c:\mydir\file.txt</code> opened<br>
  <code>tab2</code> has <code>d:\someotherdir\somefile.txt</code> opened</p>
  
  <p>If I move to <code>tab1</code> and call the open function I the <code>OpenDialog</code> should show me the contents of <code>c:\mydir\</code></p>
  
  <p>I am using Delphi 7. Any help is appreciated.</p>