Recent

Author Topic: [CLOSED] How to get AutoComplete in TComboBoxEX to work (Linux) ?  (Read 438 times)

Hartmut

  • Sr. Member
  • ****
  • Posts: 423
I want to use AutoComplete in a TComboBoxEX in ReadOnly-Mode (so user cannot edit or enter free text): suppose the ComboBox has 10 items, which start with 0..9, then I want, if the ComboBox was opened (so all items are shown) that when the user types a digit 0..9, that then the corresponding item is selected.

I got it to work on Windows, but not on Linux (nothing happens, when key 0..9 is typed).

Versions: Lazarus 2.0.6 / FPC 3.0.4 both on Windows 7 (32-bit) and Ubuntu 18.04 (64-bit). Same results with Lazarus 1.8.4 / FPC 3.0.4 on both OS.

Here is my demo (attached):
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormActivate(Sender: TObject);
  2.    var IE: TCollectionItem;
  3.        i: integer;
  4.        patch: boolean;
  5.    begin
  6.    with ComboBoxEx1 do
  7.       begin
  8.       ComboBoxEx1.AutoComplete:=true;
  9.       ComboBoxEx1.AutoCompleteOptions:=[acoAutoAppend]; {this is the Default}
  10.                {use Defaults, but with 'cbactEnabled' and without
  11.                 cbactEndOfLineComplete' because of it's documentation: }
  12.       ComboBoxEx1.AutoCompleteText:=
  13.          [cbactEnabled, {cbactEndOfLineComplete,} cbactSearchAscending];
  14.  
  15.       i:=1; {allows easy testing of different Styles}
  16.       case i of
  17.          1: Style:=csExDropDown;
  18.          2: Style:=csExDropDownList;
  19.          3: Style:=csExSimple;
  20.       end;
  21.       writeln('Style=', Style);
  22.  
  23.       ItemsEx.Clear;
  24.       ItemsEx.AddItem('1st text');
  25.       ItemsEx.AddItem('2nd text');
  26.       ItemsEx.AddItem('3rd text');
  27.  
  28.       patch:=boolean(1); {allows easy testing of with or without Patch}
  29.       if patch then      {see my posting for this Patch}
  30.          begin
  31.          Items.Clear;
  32.          for IE in ItemsEx do  Items.Add(TComboExItem(IE).Caption);
  33.          end;
  34.  
  35.       ItemIndex:=0; {select first item}
  36.       end;
  37.    end;  

I'm not sure if all my AutoComplete-settings are correct. Especially I found no documentation for TComboBoxEx.AutoCompleteOptions: https://lazarus-ccr.sourceforge.io/docs/lcl/comboex/tcomboboxex.html contains nothing about them and https://wiki.freepascal.org/TComboBoxEx is complete empty.
I played with "hundreds" of combinations for 'AutoCompleteOptions', 'AutoCompleteText' and 'Style', but on Linux nothing worked (enabling 'cbactEndOfLineComplete' made no difference).

Question 1:
Are my settings to activate the AutoComplete-Feature correct?
Does somebody know a documentation for TComboBoxEx.AutoCompleteOptions?

On Windows I had to apply a patch, which I found in https://bugs.freepascal.org/view.php?id=37008#c122611 (with this patch it works with Lazarus 2.0.6 and 1.8.4 - without this patch not).

Question 2:
Has somebody an idea how to modify this patch, that is works on Linux too?

Info: I don't want to use standard TComboBox, because
a) it has a bug on Linux, that (only in ReadOnly-Mode) always when you hover the mouse over the ComboBox, that then it's caption becomes invisible (seems to be https://bugs.freepascal.org/view.php?id=36932, I have gtk2 on KDE-Plasma with "Breeze")
b) and also with TComboBox, AutoComplete in ReadOnly-Mode does not work on Linux too.

I attached my small demo. Thanks in advance.
« Last Edit: August 12, 2020, 07:49:33 pm by Hartmut »

jamie

  • Hero Member
  • *****
  • Posts: 3507
Re: How to get AutoComplete in TComboBoxEX to work (Linux) ?
« Reply #1 on: July 28, 2020, 12:07:45 am »
I am the one that did the rework on that control but I am not happy with it..

As I was reworking it I also found other problems not directly related however.
I would suggest you use a standard TComboBox in Owner Draw mode and do all of the drawing the way you wish.

 From  your description however, it seems there could be a different way around this..

 Have you looked at TFileterComboBox ?
The only true wisdom is knowing you know nothing

Hartmut

  • Sr. Member
  • ****
  • Posts: 423
Re: How to get AutoComplete in TComboBoxEX to work (Linux) ?
« Reply #2 on: July 28, 2020, 09:41:28 am »
Hello jamie, thank you for your reply and your suggestions.

I would suggest you use a standard TComboBox in Owner Draw mode and do all of the drawing the way you wish.
This would be too difficult and too much effort for me: I feel still as a beginner to the LCL (and because of a documentation, which often doesn't exist or I can't find it or it is much too short for me (example: see 'TFilterComboBox' below), I proceed only very slow and exhausting).

I saw that ComboBox and ComboBoxEx have an AutoComplete feature and found it "nice to have" and just wanted to "enable it in about a few minutes"...

But (because I found no usable documentation for e.g. TComboBoxEx.AutoCompleteOptions and whether AutoComplete works with all 'Style's or not and which 'Style' causes ReadOnly-Mode and which Style not or what are the differences of the 3 'TComboBoxEx.Style's - during testing I found none) until now I invested about 30 hours for endless tests for endless combinations of various AutoComplete settings with all possible 'Style's for TComboBoxEx and for TComboBox on different Lazarus versions both on Linux and on Windows and endlees google searchs, where I found your bug report, which solved the problem on Windows, but unfortunately not on Linux (but I'm > 90% on Linux, so this would be much more important for me).

Sorry for crying, but I wrote this in the hope you can understand, that this suggestion would go beyond my limits for this small feature.

Quote
From  your description however, it seems there could be a different way around this..
Have you looked at TFileterComboBox ?
I had never seen TFilterComboBox before and tried it. But
 - it has no 'ReadOnly' property. Are you sure it can work in ReadOnly-Mode?
 - it has no 'Items' or 'ItemsEx' property, so I didn't know how to populate it with my strings and started google, but:
 - https://lazarus-ccr.sourceforge.io/docs/lcl/filectrl/tfiltercombobox.html helped me absolutely nothing, because it doesn't explain anything, how to use it
 - https://wiki.freepascal.org/TFilterComboBox is complete empty
 - I checked about 50 google results, but none of them explained, how to use TFilterComboBox, many of them I did not really understand, the only thing which I suppose now is, that additionally a TFileListBox or TDirectoryListBox could be needed (which I both never heared of), and so the answer to my question leads only to a new question...
So TFilterComboBox goes also for me beyond my limits for this small feature.

What I hoped is, that someone would find out, that my AutoComplete settings (see above) were wrong or that someone would know how to modify your patch, that is works on Linux too, so that I could use AutoComplete on Linux with a small, reasonable effort.

Hartmut

  • Sr. Member
  • ****
  • Posts: 423
Re: How to get AutoComplete in TComboBoxEX to work (Linux) ?
« Reply #3 on: August 12, 2020, 07:49:13 pm »
Because nobody wrote here, that my settings to enable AutoComplete were wrong, I created 2 Bug-reports:
 - https://bugs.freepascal.org/view.php?id=37558 for TComboBoxEx (Linux)
 - https://bugs.freepascal.org/view.php?id=37557 for TComboBox (Linux)

 

TinyPortal © 2005-2018