Recent

Author Topic: [SOLVED] Bug if FileListBox.Sorted in the Object Inspector  (Read 668 times)

jipété

  • Full Member
  • ***
  • Posts: 191
[SOLVED] Bug if FileListBox.Sorted in the Object Inspector
« on: February 18, 2025, 04:43:22 pm »
Linux Debian 12.9 Gtk2.24 Lazarus 3.8 FreePascal 3.2.2

The little window appears with
Code: Pascal  [Select][+][-]
  1. ShowMessage(IntToStr(flb.Items.Count));

Regards,
« Last Edit: February 19, 2025, 09:39:03 am by jipété »

dsiders

  • Hero Member
  • *****
  • Posts: 1377
Re: Bug if FileListBox.Sorted in the Object Inspector
« Reply #1 on: February 18, 2025, 05:13:23 pm »
Linux Debian 12.9 Gtk2.20 Lazarus 3.8 FreePascal 3.2.2

The little window appears with
Code: Pascal  [Select][+][-]
  1. ShowMessage(IntToStr(flb.Items.Count));

Regards,

And what are your settings in TStringList.Duplicates and TStringList.CaseSensitive?

https://lazarus-ccr.sourceforge.io/docs/rtl/classes/tstringlist.duplicates.html
https://lazarus-ccr.sourceforge.io/docs/rtl/classes/tstringlist.casesensitive.html

Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

Bart

  • Hero Member
  • *****
  • Posts: 5538
    • Bart en Mariska's Webstek
Re: Bug if FileListBox.Sorted in the Object Inspector
« Reply #2 on: February 18, 2025, 07:04:27 pm »
Sorted is handled by TCustomListBox, which asks the widgetset to handle this.
You have no influence on  how this is done.
If I follow hte code correctly, then in the end the content is copied to a TStringList with default properties and then sorted.
This should not loose an entry?

OTOH: if you set Sorted := True, and only then add the files, you may have a problem.
The internal FItems has CaseSensitive := False;
And you have no access to Items.CaseSensistive, unless you cast it to TStringList.
I guess this is what jipété does?

Chaning Sorted after the contenst were loaded should not alter the amount of items.

@jipété Can you test with attached patch?

Bart

Bart

  • Hero Member
  • *****
  • Posts: 5538
    • Bart en Mariska's Webstek
Re: Bug if FileListBox.Sorted in the Object Inspector
« Reply #3 on: February 18, 2025, 07:20:57 pm »
I created an issue in the bugtracker, so it won't be forgotten.

Bart

jipété

  • Full Member
  • ***
  • Posts: 191
Re: Bug if FileListBox.Sorted in the Object Inspector
« Reply #4 on: February 18, 2025, 11:21:14 pm »
Chaning Sorted after the content were loaded should not alter the amount of items.
Solved by using "Chaning Sorted after the content were loaded should not alter the amount of items."

And what are your settings in TStringList.Duplicates and TStringList.CaseSensitive?
Settings not used.

Thanks a lot.
« Last Edit: February 18, 2025, 11:24:28 pm by jipété »

Bart

  • Hero Member
  • *****
  • Posts: 5538
    • Bart en Mariska's Webstek
Re: [SOLVED] Bug if FileListBox.Sorted in the Object Inspector
« Reply #5 on: February 19, 2025, 01:31:48 pm »
Well, that's more of a workaround than a fix.

If you cannot apply the patch, can you try the following in your form's OnCreate:
Code: Pascal  [Select][+][-]
  1.   flb.Directory := '';  /just to invalidate
  2.   TStringList(flb.Items).CaseSensitive := False;
  3.   flb.Directory := '/path/to/desired_folder';

And leave flb.Sorted := True in the ObjectInspector.

Bart

jipété

  • Full Member
  • ***
  • Posts: 191
Re: [SOLVED] Bug if FileListBox.Sorted in the Object Inspector
« Reply #6 on: February 19, 2025, 03:39:46 pm »
I don't understand what's happening :

1st try with TStringList line commented out gives 13
Code: Pascal  [Select][+][-]
  1.   flb.Directory := '';  //just to invalidate
  2.   //TStringList(flb.Items).CaseSensitive := False;
  3.   flb.Directory := '/usr/share/fonts';
  4.   showMessage(inttostr(flb.Items.Count)); // 13

2nd try with TStringList line activated --> crash
Code: Pascal  [Select][+][-]
  1.   flb.Directory := '';  //just to invalidate
  2.   TStringList(flb.Items).CaseSensitive := False;
  3.   flb.Directory := '/usr/share/fonts'; // Crash on 3rd line
  4.   showMessage(inttostr(flb.Items.Count));

But don't loose your time : discovered yesterday a solution -- I setup the flb.Directory in the FormCreate rather than in the Object's Inspector.

Bart

  • Hero Member
  • *****
  • Posts: 5538
    • Bart en Mariska's Webstek
Re: [SOLVED] Bug if FileListBox.Sorted in the Object Inspector
« Reply #7 on: February 19, 2025, 06:02:26 pm »
The crash is in what line?
Oh, I also made a mistake: you need to set CaseSensitive to True (not False)  :-[

Bart

Bart

  • Hero Member
  • *****
  • Posts: 5538
    • Bart en Mariska's Webstek
Re: [SOLVED] Bug if FileListBox.Sorted in the Object Inspector
« Reply #8 on: February 19, 2025, 07:23:53 pm »
OK, turned on my Linux VM.
As it turns out: when the FileListBox is created, the Items is of class TExtendedStringList.
This class is derived from TStringList.

However, once the list gest updated and it has a handle allocated, Items is replaced by an instance of TGtkListStoreStringList, which is derived directly from TStringList.
And now typecasting Items to TStringList wil give an Invalid Typecast exception.

I also tested setting CaseSensitive to True in the TFileLIstBox constructor (you can typecast to TStringList there, since no handle is allocated) and that seems to work.

I'm not sure how that works, since TGtkListStoreStringList does not seem to have a CaseSensitive property...
[ETA]
TGtkListStoreStringList is case-sensitive. So it behaves as it should in this case, which is demonstarted by setting Directory when the FileListBox is already showen on the form (it has a handle): both cMap and cmap will be shown.
So, only when HandleAllocated is False, the behaviour is wrong, and can be fixed as described above.

Bart
« Last Edit: February 19, 2025, 08:25:53 pm by Bart »

Bart

  • Hero Member
  • *****
  • Posts: 5538
    • Bart en Mariska's Webstek
Re: [SOLVED] Bug if FileListBox.Sorted in the Object Inspector
« Reply #9 on: February 19, 2025, 10:42:58 pm »
Fixed in commit 3cc3475c in Lazarus main.
Merge requested to fixes 3 branch.

Bart

jipété

  • Full Member
  • ***
  • Posts: 191
Re: [SOLVED] Bug if FileListBox.Sorted in the Object Inspector
« Reply #10 on: February 20, 2025, 10:17:12 am »
Fixed in commit 3cc3475c in Lazarus main.
Merge requested to fixes 3 branch.
Thanks a lot.
Have a nice day,

 

TinyPortal © 2005-2018