* * *

Author Topic: Setting Tfilelistbox.filetype programatically  (Read 582 times)

liewald

  • Full Member
  • ***
  • Posts: 105
Setting Tfilelistbox.filetype programatically
« on: January 27, 2017, 11:44:44 am »
Lazarus 1.6.2 r53363 FPC 3.0.0 x86_64-linux-gtk 2

Hi all

having a slight problem setting the Tfilelistbox ftype to ftdirectory programatically. BAsically I want to toggle whether files or directories are shown in the filelistbox. settin the filetype to ftnormal works fine but setting it to ftdirectory results in both directories and files being shown.

here's the code

begin
   if typetoggle.ItemIndex = 0 then
  begin
    filelist.mask := '*';
    filelist.FileType :=[ftdirectory];
  end
  else
  begin
  filelist.Mask := filter.Text; // from a tedit
  filelist.filetype := [ftnormal];
  end;
  filelist.Refresh;
end; 

any Ideas?

Dave

howardpc

  • Hero Member
  • *****
  • Posts: 2059
Re: Setting Tfilelistbox.filetype programatically
« Reply #1 on: January 27, 2017, 12:19:18 pm »
If I drop a fileListBox and a button on a form and add the following it performs flawlessly. So there must be some other problem with your code. Perhaps the code to do with typetoggle...

Code: Pascal  [Select]
  1. const
  2.   isDirectory: boolean=True;
  3.  
  4. procedure TForm1.Button1Click(Sender: TObject);
  5. begin
  6.   if isDirectory then
  7.     FileListBox1.FileType:=[ftDirectory]
  8.   else
  9.     FileListBox1.FileType:=[ftNormal];
  10.   isDirectory:=not isDirectory;
  11. end;

liewald

  • Full Member
  • ***
  • Posts: 105
Re: Setting Tfilelistbox.filetype programatically
« Reply #2 on: January 27, 2017, 12:47:25 pm »
Sorry Tested your code same problem must be a version bug

Also looks as if same is happening by setting ftdirectory true in the object inspector

Dave
« Last Edit: January 27, 2017, 12:57:06 pm by liewald »

rvk

  • Hero Member
  • *****
  • Posts: 2389
Re: Setting Tfilelistbox.filetype programatically
« Reply #3 on: January 27, 2017, 12:53:29 pm »
I see the same problem in Lazarus 1.7 trunk 32 bit on Windows.

With only ftDirectory in FileType the normal files are ALSO visible.

GetMem

  • Hero Member
  • *****
  • Posts: 1956
Re: Setting Tfilelistbox.filetype programatically
« Reply #4 on: January 27, 2017, 01:08:52 pm »
This is a bug. Tested with delphi and works well.

howardpc

  • Hero Member
  • *****
  • Posts: 2059
Re: Setting Tfilelistbox.filetype programatically
« Reply #5 on: January 27, 2017, 01:27:46 pm »
Ok, it's a LCL Windows bug.
I only tried on Linux where the FileType property behaves as expected (Laz 1.6, FPC 3.0.0).
« Last Edit: January 27, 2017, 01:31:03 pm by howardpc »

liewald

  • Full Member
  • ***
  • Posts: 105
Re: Setting Tfilelistbox.filetype programatically
« Reply #6 on: January 27, 2017, 01:30:41 pm »
Sorry but I'm using 64 bit Linux!

GetMem

  • Hero Member
  • *****
  • Posts: 1956
Re: Setting Tfilelistbox.filetype programatically
« Reply #7 on: January 27, 2017, 01:31:48 pm »
@howardpc
Quote
I only tried on Linux where the FileType property behaves as expected.

See OPs first post: "Lazarus 1.6.2 r53363 FPC 3.0.0 x86_64-linux-gtk 2"

GetMem

  • Hero Member
  • *****
  • Posts: 1956
Re: Setting Tfilelistbox.filetype programatically
« Reply #8 on: January 27, 2017, 01:54:57 pm »
@liewald

Please do the following:
1. Open filectrl.pp, it's located in: $(LazarusDir)/LCL/
2. Go to the bottom part of procedure UpdateFileList(Line: 342)
3. Add the following line:
Code: Pascal  [Select]
  1. //....
  2. begin
  3.   if [csloading, csdestroying] * ComponentState <> [] then
  4.     Exit;
  5.   Clear;
  6.   if FileType <> [] then
  7.   begin
  8.     if FindFirstUTF8(
  9.       IncludeTrailingPathDelimiter(FDirectory)+AllDirectoryEntriesMask,
  10.       FileTypeToFileAttribute(FileType), Info) = 0
  11.     then
  12.       repeat
  13.         if MatchesMaskList(Info.Name,Mask) then
  14.         begin
  15.           if (ftNormal in FileType) or ((Info.Attr and AttrNotNormal) > 0) then
  16.           begin
  17.             if (Info.Attr and faDirectory) > 0 then
  18.               Items.Add('['+Info.Name+']')
  19.             else
  20.               if FileType <> [ftDirectory] then  //<--add this line(meaning: only add files to list, if the set strictly differs from ftDirectory, empty sets are checked above)
  21.                 Items.Add(Info.Name);                  
  22.           end;
  23.         end;
  24.       until FindNextUTF8(Info) <> 0;
  25.     FindCloseUTF8(Info);
  26.   end;
  27.  
  28.   UpdateSelectedFileName;
  29. end;

4. Rebuild the IDE

PS: This is just a quick fix, I did not test all the possible scenarios. You should fill in a bugreport.
« Last Edit: January 27, 2017, 02:04:28 pm by GetMem »

liewald

  • Full Member
  • ***
  • Posts: 105
Re: Setting Tfilelistbox.filetype programatically
« Reply #9 on: January 27, 2017, 02:19:38 pm »
Yyp that fixed it thanks will raise bug report now

thanks

Dave

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus