Recent

Author Topic: Problem with SelectDirectoryDialog and InitialDir  (Read 828 times)

jipété

  • Full Member
  • ***
  • Posts: 113
Problem with SelectDirectoryDialog and InitialDir
« on: June 18, 2022, 12:03:19 pm »
Hi !

Just a TSelectDirectoryDialog where InitialDir is set up to "/etc" (Linux Debian 11.3 machine) and a TButton with just one instruction (sdd.Execute).

F9 and first click on button is fine, I go in the /etc directory.
Second click is strange, sdd shows the parent of /etc.
see sdd1.png (right) and sdd2.png (wrong).

Any idea ?
Debian 11.3 Gtk 2.24 FPC 3.2.2 Laz 2.2.0

And by the way, the title of the sdd is not translated at run time (ok at design time, see 3rd png)
« Last Edit: June 18, 2022, 07:05:03 pm by jipété »

AlexTP

  • Hero Member
  • *****
  • Posts: 2401
    • UVviewsoft
Re: Problem with SelectDirectoryDialog and InitialDir
« Reply #1 on: June 18, 2022, 01:50:36 pm »
What is the value of InitialDir before the 2nd run of dialog?
Does it break?
Does component change it?

jipété

  • Full Member
  • ***
  • Posts: 113
Re: Problem with SelectDirectoryDialog and InitialDir
« Reply #2 on: June 18, 2022, 02:09:48 pm »
What is the value of InitialDir before the 2nd run of dialog?
Does it break?
Does component change it?
1- "/"
2- no
3- if not component then something else changes it.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   if sdd.Execute then ShowMessage(sdd.InitialDir) else ShowMessage(sdd.InitialDir);
  4. end;
  5.  
F9, I click the Button, the sdd shows a dialog with /etc opened, I accept and ShowMessage shows "/".
I close the prog,
F9, I click the Button, the sdd shows a dialog with /etc opened, I cancel and ShowMessage shows "/".

If I add
Code: Pascal  [Select][+][-]
  1. ShowMessage(sdd.InitialDir);
before
Code: Pascal  [Select][+][-]
  1. if sdd.Execute ...
, I get a first message showing "/etc" and at the second click of the button, the fisrt message is "/".

AlexTP

  • Hero Member
  • *****
  • Posts: 2401
    • UVviewsoft
Re: Problem with SelectDirectoryDialog and InitialDir
« Reply #3 on: June 18, 2022, 04:59:40 pm »
TSelectDirectoryDialog inherites from TOpenDialog and it changes InitialDir on choosing dir.
It depends on option ofNoChangeDir. Code shows it.

Is this behavior Delphi compatible?

Code: Pascal  [Select][+][-]
  1. function TOpenDialog.DoExecute: boolean;
  2. begin
  3.   Result:=inherited DoExecute;
  4.   if not (ofNoResolveLinks in Options) then begin
  5.     Assert(TMethod(@Self.DereferenceLinks).Code = Pointer(@TOpenDialog.DereferenceLinks),
  6.            'TOpenDialog.DoExecute: DereferenceLinks mismatch.');
  7.     //if TMethod(@Self.DereferenceLinks).Code <> Pointer(@TOpenDialog.DereferenceLinks)
  8.     //then begin
  9.     //  DereferenceLinks{%H-}; // call for compatibility
  10.     //end else
  11.     ResolveLinks;
  12.   end;
  13.   if not (ofNoChangeDir in Options) then begin
  14.     if (ExtractFilePath(Filename)<>'') then
  15.       InitialDir:=ExtractFilePath(Filename)
  16.     else if (Files.Count>0) and (ExtractFilePath(Files[0])<>'') then
  17.       InitialDir:=ExtractFilePath(Files[0]);
  18.   end;
  19.   if not Result then exit;
  20.   Result:=CheckAllFiles;
  21. end;  
« Last Edit: June 18, 2022, 05:01:48 pm by AlexTP »

jamie

  • Hero Member
  • *****
  • Posts: 6128
Re: Problem with SelectDirectoryDialog and InitialDir
« Reply #4 on: June 18, 2022, 05:05:20 pm »
have you tried doing this ?
  /etc/

add the "/" at the end ?

May not even work but..
The only true wisdom is knowing you know nothing

jipété

  • Full Member
  • ***
  • Posts: 113
Re: Problem with SelectDirectoryDialog and InitialDir
« Reply #5 on: June 18, 2022, 07:04:15 pm »
Hi,

With or without ofNoChangeDir the result is the same as the result shown this morning.

With or without "/" at the end of "/etc", the result is the same as the result shown this morning.
« Last Edit: June 18, 2022, 07:20:12 pm by jipété »

wp

  • Hero Member
  • *****
  • Posts: 11912
Re: Problem with SelectDirectoryDialog and InitialDir
« Reply #6 on: June 18, 2022, 07:24:29 pm »
Just to make sure that you don't abuse the components properties: I suppose you want to select some directory. You get this directory from the FileName property, rather than from InitialDir (I admit that naming the selected directory "Filename" is a bit unusual and misleading...). InitialDir is the directory for which the subfolders are displayed - just look at the dialog in the same way as you look at the standard TOpenDialog (from with TSelectDirectorydialog in fact inherits), with the only difference that the "files" now are "directories".

Example: you want to select a directory from /etc. Therefore, you set InitialDir to /etc, and you pick, for example, "lazarus" --> Filename will be /etc/lazarus, InitialDir will stay at /etc.

AlexTP

  • Hero Member
  • *****
  • Posts: 2401
    • UVviewsoft
Re: Problem with SelectDirectoryDialog and InitialDir
« Reply #7 on: June 18, 2022, 07:48:19 pm »
@wp,
but the component changes InitialDir. You will see that if you choose '~/something' with InitialDir='/etc'.

wp

  • Hero Member
  • *****
  • Posts: 11912
Re: Problem with SelectDirectoryDialog and InitialDir
« Reply #8 on: June 18, 2022, 11:03:31 pm »
@wp,
but the component changes InitialDir. You will see that if you choose '~/something' with InitialDir='/etc'.
Yes. But that's neat. This way the dialog opens in the directory in which the previously selected file/directory exista. If, on the other hand, you always want to open in the same directory set InitialDir immediately before calling Execute.

jipété

  • Full Member
  • ***
  • Posts: 113
Re: Problem with SelectDirectoryDialog and InitialDir
« Reply #9 on: June 20, 2022, 01:04:53 pm »
Hi,

sorry for the delay, many many many things to do at home...

I suppose you want to select some directory. You get this directory from the FileName property, rather than from InitialDir (I admit that naming the selected directory "Filename" is a bit unusual and misleading...).

Yes, here is my mistake.

If, on the other hand, you always want to open in the same directory set InitialDir immediately before calling Execute.
Needs code to save initial value of InitialDir, so I think InitialDir is not a good name, better will be StartFolder, coz' InitialDir looks like a constant, a readonly setup.
When I see/read the line InitialDir:=ExtractFilePath(Files[0]);, it looks like reversed : usually we browse for files here or there, starting browsing at InitialDir.

 

TinyPortal © 2005-2018