[SOLVED] Browsing For Folder in Linux lazarus / 32-Linux ---------------------------------------------------------------------- Sandstone · 2020-11-02 01:44 I have some existing Pascal Windows code I'm trying to port for Linux and am getting multiple errors: function TMainForm.BrowseForFolder(var Path: string): Boolean; var   BI: TBrowseInfo;   p: PItemIDList;   s, t: string; const   BIF_NONEWFOLDERBUTTON = $00000200; begin   Result := False;   ZeroMemory(@BI,SizeOf(BI));   SetLength(t,MAX_PATH);   with BI do begin     hwndOwner := Handle;     pidlRoot := nil;     pszDisplayName := PChar(t);     lpszTitle := PChar(S_SelectPathToExplore);     ulFlags := BIF_NEWDIALOGSTYLE or BIF_NONEWFOLDERBUTTON or BIF_RETURNONLYFSDIRS or BIF_VALIDATE;   end;   p := SHBrowseForFolder(BI);   if Assigned(p) then     try       SetLength(s, MAX_PATH);       if SHGetPathFromIDList(p, PChar(s)) then begin         Result := True;         Path := PChar(s);       end;     finally       CoTaskMemFree(p);     end; end; MainFormUnit.pas(2152,7) Error: Identifier not found "TBrowseInfo" MainFormUnit.pas(2153,6) Error: Identifier not found "PItemIDList" MainFormUnit.pas(2159,3) Error: Identifier not found "ZeroMemory" MainFormUnit.pas(2162,5) Error: Identifier not found "hwndOwner" MainFormUnit.pas(2163,5) Error: Identifier not found "pidlRoot" MainFormUnit.pas(2164,5) Error: Identifier not found "pszDisplayName" MainFormUnit.pas(2165,5) Error: Identifier not found "lpszTitle" MainFormUnit.pas(2166,5) Error: Identifier not found "ulFlags" MainFormUnit.pas(2166,16) Error: Identifier not found "BIF_NEWDIALOGSTYLE" MainFormUnit.pas(2166,63) Error: Identifier not found "BIF_RETURNONLYFSDIRS" MainFormUnit.pas(2166,87) Error: Identifier not found "BIF_VALIDATE" MainFormUnit.pas(2168,8) Error: Identifier not found "SHBrowseForFolder" Am I missing a package or unit that handles this? Units I have are: uses   LCLIntf, LCLType, LMessages, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,   Dialogs, IniFiles, StdCtrls, Grids, ComCtrls, Types,   ExtCtrls, Buttons, Organ, ToolWin, Menus, VirtualTrees, ImgList,   FakeActiveX,  CheckLst, ObjectMatrixFrameUnit,   Themes,   {project units}   WoodFormUnit, ScanFormUnit, ExportFormUnit,   WarningFormUnit, ConfigurationFormUnit, SplashFormUnit; ---------------------------------------------------------------------- Handoko · 2020-11-02 03:19 Free Pascal Compiler is a cross platform compiler. But that does not mean you can just compile all the source codes that work on a platform to other platforms. The codes must be written to support cross compiling, which usually mean not using any platform or OS specific function. In the list of units you provided, I think these are not able to compile to Linux: Organ, ToolWin, FakeActiveX, ObjectMatrixFramUnit. The name ToolWin suggests it works on Windows only. And as far as I know Linux does not support ActiveX technology. If you really want to make the existing BrowseForFolder code to be able to compile to Linux, you have some possible solutions: - If you have the source codes of all the units, study them and manually convert them to Linux-friendly units - Or you can share all of them on the forum and ask someone to help you if the licenses allow you to do that - You can consider to create a bounty for the task But I think the most easiest thing to do is abandon the code and write a new cross-compile-friendly code. Browse for folder does not sound difficult. Not exactly what you want but Lazarus itself has components that you can use or study: TOpenDialog, TFileListBox, TShellListView. ---------------------------------------------------------------------- lucamar · 2020-11-02 05:34 All that code is entirely Windows-specific so you won't be able to make it work on Linux. Also, note that, generally speaking, Linux neither has or need a "Browse for folder" dialog, since most, if not all, of its funcions are present in the standard "Open file" dialog or its Lazarus specialization TSelectDirectory. If you really want one looking more or less like the Windows one you might mimic it by building your own; the easiest way will probably be using a TShellListView, as Handoko said. But if I were you I would just replace all that for a SelectDirectoryDialog for all platforms. ---------------------------------------------------------------------- Sandstone · 2020-11-02 17:14 Quote from: Handoko on November 02, 2020, 04:19:56 amBut I think the most easiest thing to do is abandon the code and write a new cross- compile-friendly code. I expected that this would be where I would end up with this.  No worries, I still have the Windows version that will run in Wine 5.0.2 ---------------------------------------------------------------------- balazsszekely · 2020-11-02 19:55 @Sandstone There is a crossplatform TSelectDirectoryDialog component(Dialog palette) shipped with Lazarus. If you check Options->ofOldStyleDialog it looks exactly like the one created with your BrowseForFolder function. ---------------------------------------------------------------------- Bart · 2020-11-02 20:21 If you insist on using the old function (so you don't have to change the code that is calling it), try something like this: 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 TMainForm.BrowseForFolder(var Path: string): Boolean;var  Dlg: TSelectDirectoryDialog;begin  Dlg := TSelectDirectoryDialog.Create(nil);  try    Dlg.InitialDir := Path;  Result := Dlg.Execute;    if Result then      Path := Dlg.FileName;  finally   Dlg.Free;  end;end; Bart