var Directory, Mask: String; sr: TSearchRec;begin Directory := 'c:\some\directory\'; Mask := '*.ctp'; if FindFirstUTF8(Directory+Mask,faAnyFile,sr)=0 then repeat YourListBox.Items.Add(sr.Name); until FindNextUTF8(sr)<>0; FindCloseUTF8(sr);end;
ListBox1.Items:=FindAllFiles('c:\folder', '*.ctp', true {search in subdirectory});
OrCode: [Select]ListBox1.Items:=FindAllFiles('c:\folder', '*.ctp', true {search in subdirectory});
var list: TStringList;begin list := FindAllFiles(('c:\folder', '*.ctp', true {search in subdirectory}); List.Items := list; // or better (since is does not give the impression that a pointer is copied): // List.Items.Assign(list); list.Free;end;
var list: TStringList;begin list := FindAllFiles(('c:\folder', '*.ctp', true {search in subdirectory}); ListBox.Items := list; // or better (since is does not give the impression that a pointer is copied): // ListBox.Items.Assign(list); list.Free;end;
The correct way, in my eyes, would beCode: [Select]var list: TStringList;begin list := FindAllFiles(('c:\folder', '*.ctp', true {search in subdirectory}); List.Items := list; // or better (since is does not give the impression that a pointer is copied): // List.Items.Assign(list); list.Free;end;
Old topic.Have a question, tho:Quote from: wp on March 31, 2015, 03:45:26 pmThe correct way, in my eyes, would beCode: [Select]var list: TStringList;begin list := FindAllFiles(('c:\folder', '*.ctp', true {search in subdirectory}); List.Items := list; // or better (since is does not give the impression that a pointer is copied): // List.Items.Assign(list); list.Free;end;If the pointer to list is freed like this, will it not delete the data in the list - and thus the strings in the listbox.items?
This is a beautiful example why I don't like the FindAllFiles function and this construction.