Filling a listbox from a dir lazarus / 61-Beginners ---------------------------------------------------------------------- JLWest · 2019-03-02 05:10 I copied the following from a post and I believe   @Wp wrote the code. I can't find the post and can't get the code to compile. I want to pass a file name into the procedure LoadFileBox. I don't want directories or sub directories. Just the file in the specified directory. I get an error line 40. 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 unit Unit1;{$mode objfpc}{$H+}interface uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    ListBox1: TListBox;    procedure Button1Click(Sender: TObject);  private   public    procedure LoadFileBox(aFName: String);   end; var  Form1: TForm1;implementation {$R *.lfm} procedure TForm1.Button1Click(Sender: TObject); Var   S : String = 'c:\folder';  begin LoadFileBox(S);end; procedure TForm1.LoadFileBox(aFName: String);  var  list: TStringList;  begin    list := FindAllFiles((aFName + '*' , False {don't search in subdirectory});begin    ListBox.Items := list;    list.Free;  end;  end;end. ---------------------------------------------------------------------- engkin · 2019-03-02 05:33 Probably LoadFileBox should be: 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.LoadFileBox(aFName: String);var  list: TStringList;begin  list := FindAllFiles((aFName + '*' , False {don't search in subdirectory});  ListBox.Items := list;  list.Free;end; ---------------------------------------------------------------------- JLWest · 2019-03-02 06:01 I get the following error.  unit1.pas(40,38) Fatal: Syntax error, ")" expected but "," found It dosen't like the ',' after the  '*'  at line 5. 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.LoadFileBox(aFName: String);var  list: TStringList;begin  list := FindAllFiles((aFName + '*' , False {don't search in subdirectory});  ListBox.Items := list;  list.Free;end; ---------------------------------------------------------------------- engkin · 2019-03-02 06:32 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   list := FindAllFiles(aFName,'*', False {don't search in subdirectory}); ---------------------------------------------------------------------- Bart · 2019-03-02 11:53 Don't we have a TFileListBox that does exactly this? Bart ---------------------------------------------------------------------- flowCRANE · 2019-03-02 12:57 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.LoadFileBox(const ASearchPath, ASearchMask: String);begin  ListBox1.Items.BeginUpdate();  FindAllFiles(ListBox1.Items, ASearchPath, ASearchMask, False);  ListBox1.Items.EndUpdate();end; Calling: 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 LoadFileBox('C:\Windows\', '*'); Quote from: Bart on March 02, 2019, 12:53:05 pmDon't we have a TFileListBox that does exactly this? Indeed — the Directory and Mask properties allows to do the same. ---------------------------------------------------------------------- lucamar · 2019-03-02 13:07 Quote from: Bart on March 02, 2019, 12:53:05 pmDon't we have a TFileListBox that does exactly this? Bart Yes. The difference is that while TFilelistBox shows only the file names, FindAllFiles() returns the full path+name. ---------------------------------------------------------------------- Bart · 2019-03-02 13:07 Quote from: furious programming on March 02, 2019, 01:57:03 pmQuote from: Bart on March 02, 2019, 12:53:05 pmDon't we have a TFileListBox that does exactly this? Indeed — the Directory and Mask properties allows to do the same. I know, I did some work on that in the past. Bart ---------------------------------------------------------------------- Bart · 2019-03-02 13:09 Quote from: lucamar on March 02, 2019, 02:07:11 pmYes. The difference is that while TFilelistBox shows only the file names, FindAllFiles() returns the full path+name. IIRC then TFileListBox has a Directory property (I'm too lazy to look it up), so Path is known (at least to the programmer). Bart ---------------------------------------------------------------------- lucamar · 2019-03-02 13:44 Quote from: Bart on March 02, 2019, 02:09:08 pmIIRC then TFileListBox has a Directory property (I'm too lazy to look it up), so Path is known (at least to the programmer). Yes, of course, but 1) It's more a matter of UI than of code; and 2) With FindAllFiles+ListBox you don't have to reconstruct each file-name if you need it. And it's not that much slower either, although, obviously, uses more memory It would be otherwise if TFileListBox had an option to show fully- qualified file-names ... ---------------------------------------------------------------------- jamie · 2019-03-02 14:45 There is no need to use "FindAllFiles" the FilelistBox has all that is needed in it.. you set the mask, directly etc, and call the UpdateFileList ---------------------------------------------------------------------- Bart · 2019-03-02 16:41 The FileName property of TFileListBox already includes the directory part. Bart ---------------------------------------------------------------------- lucamar · 2019-03-02 17:18 Quote from: Bart on March 02, 2019, 05:41:18 pmThe FileName property of TFileListBox already includes the directory part. Bart Yes, for the selected file. What if you want to iterate the list doing something with each file? You could select, in code, each file-line and read FileName but then where is the advantage of TFileListBox? And don't forget that the FileListBox is still not showing the path. What I'm trying to say is that yes, TFileListBox is convenient and very useful for some tasks; for others, with other requirements, one could do worse than using FindAllFiles+TListBox. ---------------------------------------------------------------------- Bart · 2019-03-02 17:24 Derive from TFileControl and make it display fully qualified names wouldn't be that hard I think. No need to re-implement all the other logic then. Off-topic: didn't we also have a TDriveComboBox, or is that just old Delphi? Bart ---------------------------------------------------------------------- JLWest · 2019-03-03 16:39 I'm Using a TFileList box to display a directory's files. Is it possible with this control to also show the sub directories in the listbox or is it only for files.. ---------------------------------------------------------------------- lucamar · 2019-03-03 17:13 Quote from: JLWest on March 03, 2019, 05:39:02 pmI'm Using a TFileList box to display a directory's files. Is it possible with this control to also show the sub directories in the listbox or is it only for files.. Yes, it's possible. Set FileListBox.FileType to FileListBox.FileType + [ftDirectory]; either in code or in the Object Inspector. Or viceversa to not show them. ---------------------------------------------------------------------- JLWest · 2019-03-03 17:39 Thanks ---------------------------------------------------------------------- lucamar · 2019-03-03 18:36 I know you'll probably not need it but just in case (and because I was bored ) I've prepared a basic mini-demo of FileListBox. Have fun! ---------------------------------------------------------------------- JLWest · 2019-03-03 22:40 Thanks I'll try it out.