Problem with SelectDirectoryDialog and InitialDir lazarus / 31-LCL ---------------------------------------------------------------------- jipété · 2022-06-18 10:03 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) ---------------------------------------------------------------------- AlexTP · 2022-06-18 11:50 What is the value of InitialDir before the 2nd run of dialog? Does it break? Does component change it? ---------------------------------------------------------------------- jipété · 2022-06-18 12:09 Quote from: AlexTP on June 18, 2022, 01:50:36 pmWhat 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);begin  if sdd.Execute then ShowMessage(sdd.InitialDir) else ShowMessage(sdd.InitialDir);end; 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ShowMessage(sdd.InitialDir); before Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if sdd.Execute ..., I get a first message showing "/etc" and at the second click of the button, the fisrt message is "/". ---------------------------------------------------------------------- AlexTP · 2022-06-18 14:59 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function TOpenDialog.DoExecute: boolean;begin  Result:=inherited DoExecute;  if not (ofNoResolveLinks in Options) then begin    Assert(TMethod(@Self.DereferenceLinks).Code = Pointer(@TOpenDialog.DereferenceLinks),           'TOpenDialog.DoExecute: DereferenceLinks mismatch.');    //if TMethod(@Self.DereferenceLinks).Code <> Pointer(@TOpenDialog.DereferenceLinks)    //then begin    //  DereferenceLinks{%H-}; // call for compatibility    //end else    ResolveLinks;  end;  if not (ofNoChangeDir in Options) then begin    if (ExtractFilePath(Filename)<>'') then      InitialDir:=ExtractFilePath(Filename)    else if (Files.Count>0) and (ExtractFilePath(Files[0])<>'') then      InitialDir:=ExtractFilePath(Files[0]);  end;  if not Result then exit;  Result:=CheckAllFiles;end; ---------------------------------------------------------------------- jamie · 2022-06-18 15:05 have you tried doing this ?   /etc/ add the "/" at the end ? May not even work but.. ---------------------------------------------------------------------- jipété · 2022-06-18 17:04 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. ---------------------------------------------------------------------- wp · 2022-06-18 17:24 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 · 2022-06-18 17:48 @wp, but the component changes InitialDir. You will see that if you choose '~/something' with InitialDir='/etc'. ---------------------------------------------------------------------- wp · 2022-06-18 21:03 Quote from: AlexTP 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'. 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é · 2022-06-20 11:04 Hi, sorry for the delay, many many many things to do at home... Quote from: wp on June 18, 2022, 07:24:29 pmI 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. Quote from: wp on June 18, 2022, 11:03:31 pmIf, 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.