Recent

Author Topic: How to enable TOpenDialog.InitialDir in Windows 7?  (Read 12182 times)

dkjMusic

  • Full Member
  • ***
  • Posts: 146
How to enable TOpenDialog.InitialDir in Windows 7?
« on: September 30, 2011, 03:01:12 pm »
I have the following code, but Windows insists on opening the last opened directory when the open dialog is executed:

  ProjectOpenDialog.InitialDir := Settings.ProjectDirectory;
  SetCurrentDir(ProjectOpenDialog.InitialDir);
Windows 7 Ultimate/32 bit;
Lazarus 0.9.31/Rev 33300;
FPC 2.7.1/Rev 19464;
GDB 7.0.50;
(via CodeTyphon 2.30)

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: How to enable TOpenDialog.InitialDir in Windows 7?
« Reply #1 on: September 30, 2011, 03:25:48 pm »
Try to change "filename".

Code: [Select]
ProjectOpenDialog.Filename := Settings.ProjectDirectory;
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

dkjMusic

  • Full Member
  • ***
  • Posts: 146
Re: How to enable TOpenDialog.InitialDir in Windows 7?
« Reply #2 on: September 30, 2011, 05:14:18 pm »
Try to change "filename".

Code: [Select]
ProjectOpenDialog.Filename := Settings.ProjectDirectory;
That "sorta" worked. The dialog still opened in the last opened directory with the Settings.ProjectDirectory text in the filename box. Clicking the <Open> button then took me to the ProjectDirectory, but the user might not know what was happening. I believe that Windows default behavior is fighting me on this one.

Any thing else I should try?
Windows 7 Ultimate/32 bit;
Lazarus 0.9.31/Rev 33300;
FPC 2.7.1/Rev 19464;
GDB 7.0.50;
(via CodeTyphon 2.30)

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: How to enable TOpenDialog.InitialDir in Windows 7?
« Reply #3 on: September 30, 2011, 05:59:35 pm »
This (call it before OpenDialog.Execute):
Code: [Select]
ProjectOpenDialog.Filename := ProjectOpenDialog.InitialDir;
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

dkjMusic

  • Full Member
  • ***
  • Posts: 146
Re: How to enable TOpenDialog.InitialDir in Windows 7?
« Reply #4 on: September 30, 2011, 06:18:40 pm »
This (call it before OpenDialog.Execute):
Code: [Select]
ProjectOpenDialog.Filename := ProjectOpenDialog.InitialDir;
I got the same.
Windows 7 Ultimate/32 bit;
Lazarus 0.9.31/Rev 33300;
FPC 2.7.1/Rev 19464;
GDB 7.0.50;
(via CodeTyphon 2.30)

Bart

  • Hero Member
  • *****
  • Posts: 5713
    • Bart en Mariska's Webstek
Re: How to enable TOpenDialog.InitialDir in Windows 7?
« Reply #5 on: September 30, 2011, 07:28:11 pm »
Strange,

Code: [Select]
  if InitialDir <> '' then
  begin
    if Succeeded(SHCreateItemFromParsingName(PWideChar(UTF8ToUTF16(InitialDir)), nil, IShellItem, DefaultFolderItem)) then
      ADialog.SetDefaultFolder(DefaultFolderItem);
  end;

I verified that Succeeded(SHCreateItemFromParsingName()) actually returns True for existing dirs (and false for non-existing) and that GetFileName(DefaultFolderItem) in fact returns the right name, but nevertheless InitialDir isn't set at all.
ADialog.SetDefaultFolder resturns 0 (which Succeded() says is True, indicating that all went OK).

Bart
« Last Edit: September 30, 2011, 07:36:55 pm by Bart »

dkjMusic

  • Full Member
  • ***
  • Posts: 146
Re: How to enable TOpenDialog.InitialDir in Windows 7?
« Reply #6 on: September 30, 2011, 08:23:57 pm »
Bart, so what does this mean?
Windows 7 Ultimate/32 bit;
Lazarus 0.9.31/Rev 33300;
FPC 2.7.1/Rev 19464;
GDB 7.0.50;
(via CodeTyphon 2.30)

Bart

  • Hero Member
  • *****
  • Posts: 5713
    • Bart en Mariska's Webstek
Re: How to enable TOpenDialog.InitialDir in Windows 7?
« Reply #7 on: October 01, 2011, 11:17:41 pm »
Bart, so what does this mean?

I really do not have a clue.
I was just investigating if something obvious went wrong in that code.

Maybe you should report it on the bugtracker.

Bart

Bart

  • Hero Member
  • *****
  • Posts: 5713
    • Bart en Mariska's Webstek
Re: How to enable TOpenDialog.InitialDir in Windows 7?
« Reply #8 on: October 01, 2011, 11:50:00 pm »
Cahnging the code in Win32WSDialogs.pp to this seems to work:

Code: [Select]
if InitialDir <> '' then
  begin
    if Succeeded(SHCreateItemFromParsingName(PWideChar(UTF8ToUTF16(InitialDir)), nil, IShellItem, DefaultFolderItem)) then
      ADialog.SetFolder(DefaultFolderItem);  //SetFolder, not SetDefaultFolder
end;

I'm unsure however, if this is the correct way.

Anyway I posted it on the bugtracker (http://bugs.freepascal.org/view.php?id=20387)

Bart
« Last Edit: October 02, 2011, 12:04:34 am by Bart »

Bart

  • Hero Member
  • *****
  • Posts: 5713
    • Bart en Mariska's Webstek
Re: How to enable TOpenDialog.InitialDir in Windows 7?
« Reply #9 on: October 05, 2011, 03:37:35 pm »
Fixed in r32654.

Bart

 

TinyPortal © 2005-2018