TListbox behaviour under OpenSuse/Gnome lazarus / 31-LCL ---------------------------------------------------------------------- Chris_h174 · 2020-08-27 13:32 Hi all, I'm new here but been using Lazarus for about 10 years after ditching Delphi 5! I have program that uses a listbox and it has a peculiar behaviour... Unde Linux, if I populate the list and type with focus on it, if the first row is selected I get an error : [Project project1 raised exception class 'External: SIGFPE'.  In file 'laztracer.pas' at line 50] If I press a key with any later line selected then I get expected behaviour.  Win_7_64 appears to compile with "normal" behaviour. Another difference (am I allowed two?) is that the Windows version only locates according to the first character of a line whilst Linux allows me to keep typing and it continues to locate.  That said, although the highlight follows the typing, it doesn't actually select the row; I have to press or click on it to make ItemIndex correct. (Maybe that's three issues) Lazarus 2.02 on both Win7 & Opensuse 15.1 Cheers Chris_H174 ---------------------------------------------------------------------- Handoko · 2020-08-27 13:50 Hello Chris_h174, Welcome to the forum. I use TListBox pretty often on Ubuntu Mate GTk2, so far they work correctly, without any exception nor error. I believe you did it wrong. If you can provide the compile-able source code we may able to tell where you did it wrong. If you're not willing to publicize the whole source code, you can write a simplified demo that can show the issue. To do it: Create a new folder, copy and paste all the necessary files into it except: the binary (exe file), *.bak, lib and backup folders. Compress the folder and send the zip here. Maybe you can download and try the demo I wrote, it generates a TListBox on a popup at runtime: https://forum.lazarus.freepascal.org/index.php/topic,37369.msg250939.h tml#msg250939 Does it run correctly on your test? Do you get any error? ---------------------------------------------------------------------- Chris_h174 · 2020-08-27 15:06 Thanks for your prompt reply.  I had a quick look at your example on the link and it doesn't quite cover my issue.  I have created a "bald" project that just illustrates it (attached). Compile and run (I'm using 64-bit on Opensuse) Click Load to put some lines in then click line 2 in the listbox and press a key.  No problem.  Select line 1 and press a key - I get the exception every time on Linux. Win7_64 on the same source works OK. Added: I can see [Msg = 'TGtkListStoreStringList.Get Out of bounds.' var  Msg: string /usr/lib64/lazarus/components/lazutils/laztracer.pas(43,35) Package LazUtils] In LazTracer Thanks PS How do I put my OS, FPC vers etc. in my signature please? [Edit: The option appeared several days later and signature now gets retrospectively added to all previous posts!] ---------------------------------------------------------------------- Chris_h174 · 2020-08-27 16:01 I've now tried your example and it works OK. Trying hard to break it. Chris ---------------------------------------------------------------------- Handoko · 2020-08-27 16:42 I think I have solved the issue. Please test it: 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.lb1SelectionChange(Sender: TObject; User: boolean);begin  if lb1.ItemIndex < 0 then Exit;  sb1.Panels[0].Text := lb1.Items[lb1.ItemIndex];end; ---------------------------------------------------------------------- Chris_h174 · 2020-08-27 17:42 Wow.  That certainly fixes the exception but why, when Itemindex is 0? Any views on the issue of a row being highlighted when itemIndex relates to another row? Cheers Chris ---------------------------------------------------------------------- Handoko · 2020-08-27 17:46 I don't know. But I think if doing searching on the listbox and nothing satisfy the keyword, the index becomes -1. Just my guess, need someone more expert to answer. ---------------------------------------------------------------------- lucamar · 2020-08-27 17:53 Quote from: Chris_h174 on August 27, 2020, 05:06:08 pmPS How do I put my OS, FPC vers etc. in my signature please? In the top row of links, select "Profile->Forum profile"; then change the "Signature" in the page that appears. ---------------------------------------------------------------------- lucamar · 2020-08-27 17:59 Quote from: Chris_h174 on August 27, 2020, 07:42:40 pmAny views on the issue of a row being highlighted when itemIndex relates to another row? That usually happens when MultiSelect is True. In that case you might have one or several items "selected" while the focused item (the one pointed to by ItemIndex) might be another one. When MultiSelect is false there can be only one item "selected" which happens to be also the one that has the focus unless ExtendedSelect is True, in which case the last item being selected is also the current one pointed to by ItemIndex. The point, really, is that the only case where the item at ItemIndex might be several "rows" separated from the "selected" item(s) is when MultiSelect is set to True. HTH. ---------------------------------------------------------------------- Chris_h174 · 2020-08-27 21:32 Quote from: lucamar on August 27, 2020, 07:53:02 pmQuote from: Chris_h174 on August 27, 2020, 05:06:08 pmPS How do I put my OS, FPC vers etc. in my signature please? In the top row of links, select "Profile->Forum profile"; then change the "Signature" in the page that appears. Thanks for that. That option doesn't appear for me, so I guess I'm not old enough yet  Chris ---------------------------------------------------------------------- winni · 2020-08-27 22:47 Hi! Show me your passport and I show you a screenshot.... Take forum profile. At the botton is the memo field for the signature. Winni ---------------------------------------------------------------------- lucamar · 2020-08-28 01:34 Quote from: Chris_h174 on August 27, 2020, 11:32:19 pmQuote from: lucamar on August 27, 2020, 07:53:02 pm[...] In the top row of links, select "Profile->Forum profile"; then change the "Signature" in the page that appears. Thanks for that. That option doesn't appear for me, so I guess I'm not old enough yet  Chris Which one: Profile or Forum Profile? Nevertheless it's strange; IIRC it should be there from day one. An alternative, if "Profile" appears, is to click it, disregarding the submenu, and try to access "Forum Profile" from the "Modify Profile" option in the new page (see image). ---------------------------------------------------------------------- Chris_h174 · 2020-08-28 08:27 QuoteThat usually happens when MultiSelect is True. In that case you might have one or several items "selected" while the focused item (the one pointed to by ItemIndex) might be another one. When MultiSelect is false there can be only one item "selected" which happens to be also the one that has the focus unless ExtendedSelect is True, in which case the last item being selected is also the current one pointed to by ItemIndex. The point, really, is that the only case where the item at ItemIndex might be several "rows" separated from the "selected" item(s) is when MultiSelect is set to True. HTH. I've tried playing with Multiselect and ExtendedSelect and neither help. On the demo I sent (slightly tweaked) I get this: Sorry, attached. It won't let me embed a png inline.  You can see from the status bar that itemindex is pointing to the line before the highlighted one.  If I press another key then it updates correctly.  So, I have to press one more key than is necessary in order to make it synchronise. Chris ---------------------------------------------------------------------- lucamar · 2020-08-28 08:57 I can't reproduce with the original example*; you might want to post the  tweaked one to let us see if something changed. In the meantime, test with the attached project and tell me if it also fails, can you? Note, though, that while the search is in progress and until it can unequivocally select a unique item the OnSelectionChange event won't be fired; might that be what you're seeing? If so, there is nothing you can do: that's how the GTK2 widgetset works. * Tested on Xubuntu 18.04 x86_64 ---------------------------------------------------------------------- Chris_h174 · 2020-08-28 08:58 Quote from: lucamar on August 28, 2020, 03:34:57 amQuote from: Chris_h174 on August 27, 2020, 11:32:19 pmQuote from: lucamar on August 27, 2020, 07:53:02 pm[...] In the top row of links, select "Profile->Forum profile"; then change the "Signature" in the page that appears. Thanks for that. That option doesn't appear for me, so I guess I'm not old enough yet  Chris Which one: Profile or Forum Profile? Nevertheless it's strange; IIRC it should be there from day one. An alternative, if "Profile" appears, is to click it, disregarding the submenu, and try to access "Forum Profile" from the "Modify Profile" option in the new page (see image). Everywhere I look I only have the basic profile settings in Account Settings.  It must be configured-out somewhere out of my control.  Just using Firefox under OpenSuse Leap 15.1 fully up-to-date.  This isn't really the right forum for this so I'll drop it.  A nuisance though. Cheers Chris ---------------------------------------------------------------------- Chris_h174 · 2020-08-28 09:27 Quote from: lucamar on August 28, 2020, 10:57:41 amI can't reproduce with the original example*; you might want to post the  tweaked one to let us see if something changed. In the meantime, test with the attached project and tell me if it also fails, can you? Note, though, that while the search is in progress and until it can unequivocally select a unique item the OnSelectionChange event won't be fired; might that be what you're seeing? If so, there is nothing you can do: that's how the GTK2 widgetset works. * Tested on Xubuntu 18.04 x86_64 Thanks for your time Lucamar I can't get your example to link.  I've been getting "crtbeginS.o" & "crtendS.o" not found for ages but it's never actually prevented linking. My changes were simply to add ItemIndex to the StatusBar readout and add a listbox line with more common leading characters. Chris ---------------------------------------------------------------------- Chris_h174 · 2020-09-01 08:14 Quote from: Chris_h174 on August 28, 2020, 11:27:44 amQuote from: lucamar on August 28, 2020, 10:57:41 amI can't reproduce with the original example*; you might want to post the  tweaked one to let us see if something changed. In the meantime, test with the attached project and tell me if it also fails, can you? Note, though, that while the search is in progress and until it can unequivocally select a unique item the OnSelectionChange event won't be fired; might that be what you're seeing? If so, there is nothing you can do: that's how the GTK2 widgetset works. * Tested on Xubuntu 18.04 x86_64 Thanks for your time Lucamar I can't get your example to link.  I've been getting "crtbeginS.o" & "crtendS.o" not found for ages but it's never actually prevented linking. My changes were simply to add ItemIndex to the StatusBar readout and add a listbox line with more common leading characters. Chris OK.  So I managed to get it to link by selecting "Release" in Project|Options... It still misbehaves IMHO.  Screenshot below shows "Item th" typed and correct line highlighted but ItemIndex still on "Item two".  If I type an extra character (can be a ) it corrects itself.  It looks to me as if ItemIndex lags the highlight by one character. Thanks Chris ---------------------------------------------------------------------- jamie · 2020-09-01 14:36 I am not a Linux expert but maybe you need to perform a UPDATE during the KeyDown cycle..? ListBox.Update.. or Repaint... etc ---------------------------------------------------------------------- Chris_h174 · 2020-09-01 14:54 Quote from: jamie on September 01, 2020, 04:36:36 pmI am not a Linux expert but maybe you need to perform a UPDATE during the KeyDown cycle..? ListBox.Update.. or Repaint... etc I'm very wise but... This is the built-in behaviour under gtk2.  I'm not intercepting keydown. Chris ---------------------------------------------------------------------- lucamar · 2020-09-01 15:06 It's in fact the default behaviour in GTk. The widgetset uses a relatively small delay to cope with slow typists and in case you made a mistake and have to delete the latest char(s) before admiting (and searching for) the  string. When you type some (more) char it "knows" that the previous ones are probably correct, so it acknowledges all but the more recent. You can see this in, for example, the file manager (Nautilus, Thunar, pcfman, ...): the corresponding file selection goes always a little behind your typing of the name. ---------------------------------------------------------------------- jamie · 2020-09-01 15:20 Sounds like the gtk was designed for slow old timers ! ---------------------------------------------------------------------- lucamar · 2020-09-01 16:12 Quote from: jamie on September 01, 2020, 05:20:31 pmSounds like the gtk was designed for slow old timers ! I know you say it tongue-in-cheek but ... not really; in this particular case it does it to avoid having to do a relatively costly operation (the search) repeatedly when it's not really needed. Think, for example, of a list of image files from a camera: there might be thousands and all of them start with the same four characters, hundreds start with the same five or six, and so on. Delaying the (full) search until the user stops typing makes it much more responsive. Note also that at any time you can press to tell the widgetset to update the widget so its not really that cumbersome (most of the times ) ---------------------------------------------------------------------- Chris_h174 · 2020-09-02 08:07 Quote from: lucamar on September 01, 2020, 06:12:58 pmQuote from: jamie on September 01, 2020, 05:20:31 pmSounds like the gtk was designed for slow old timers ! I know you say it tongue-in-cheek but ... not really; in this particular case it does it to avoid having to do a relatively costly operation (the search) repeatedly when it's not really needed. Think, for example, of a list of image files from a camera: there might be thousands and all of them start with the same four characters, hundreds start with the same five or six, and so on. Delaying the (full) search until the user stops typing makes it much more responsive. Note also that at any time you can press to tell the widgetset to update the widget so its not really that cumbersome (most of the times ) But I AM a slow old-timer. I think the reasoning is flawed.  If it needs to behave like that then the highlight should too.  It is indicating to the user that they have selected an item when they have actually selected a different one!  In fact it doesn't always have to do an entire search, it only has to compare with the currently selected one and re-search if it differs. Chris