TDBLookupCombobox results not sorted? lazarus / 16-Databases ---------------------------------------------------------------------- bill0287 · 2013-12-05 03:49 I have a TDBLookupCombobox linked to a DBf that is sorted by index, but the results in the combobox are not sorted...is this a bug or did I miss something? ---------------------------------------------------------------------- engkin · 2013-12-05 05:21 What did you do to make sure that the TDbf is sorted by index? ---------------------------------------------------------------------- LuizAmérico · 2013-12-05 10:26 To be sure the dataset is sorted, add a dbgrid and link the dataset to it. If the dataset is sorted in the dbgrid and not in the dblookpu then add a bugreport with a sample project ---------------------------------------------------------------------- bill0287 · 2013-12-05 17:18 My DBGrid showed the data was sorted properly. Here is a very small test program. Could someone look at this and confirm I am seeing a bug...I don't want to file one if I am making a simple mistake.  Thanks. ---------------------------------------------------------------------- BigChimp · 2013-12-05 17:41 Setting the DBLookupCombobox Sorted property to true did the trick for me. TBH, no idea if/how you can influence sorting otherwise. Then again, I'm not really a GUI guy... ---------------------------------------------------------------------- bill0287 · 2013-12-05 17:48 ugh. That did it for me too...I thought I had set that in the code, but I guessed I missed it. That's why I didn't want to file the bug right away. Thanks for the clear set of eyes! ---------------------------------------------------------------------- taazz · 2013-12-05 18:23 Actually if I understand the issue correctly then I think that the bug report should be filed as well. If the dataset, in this case TDBF, is already sorted then tdblookupcombo should show the data sorted as well and not ignore the users choices. Setting the sorted property should do a client sort on top of the existing order but it should not ignore the existing order if it is not set. ---------------------------------------------------------------------- engkin · 2013-12-05 19:26 I agree with Taazz. If you change your sample code a little bit so that you can switch between two different indexes when you click SortButton: Code: [Select]procedure TForm1.SortButtonClick(Sender: TObject); begin   if DBf1.IndexName='idxLast' then     DBf1.IndexName:='idxFirst'   else     DBf1.IndexName:='idxLast'; end; You will notice that it does not follow the index you choose, with or without Sorted := true; There is a missing call to a private procedure UpdateLookup in the TDBLookupComboBox. As a workaround, after changing the index simply use anything that would call UpdateLookup, like Code: [Select]  DBLookupComboBox1.KeyField := DBLookupComboBox1.KeyField; Test it on your sample code: Code: [Select]procedure TForm1.SortButtonClick(Sender: TObject); begin   if DBf1.IndexName='idxLast' then     DBf1.IndexName:='idxFirst'   else     DBf1.IndexName:='idxLast';   DBLookupComboBox1.KeyField := DBLookupComboBox1.KeyField; end; ---------------------------------------------------------------------- bill0287 · 2013-12-05 20:58 Thanks ! I went ahead and filed a bug report: http://bugs.freepascal.org/view.php?id=25400 ---------------------------------------------------------------------- BigChimp · 2013-12-05 22:42 I think you should have filed it as a Lazarus bug as it pertains to a data-bound control, not necessarily (and probably not) the underlying FPC sqldb implementation. I've posted on the bug report with a request for reassignment so the Lazarus devs can have a look... ---------------------------------------------------------------------- bill0287 · 2013-12-05 23:32 I never filed a bug before, so I took my best shot - thanks for looking it over and adding comments ---------------------------------------------------------------------- LuizAmérico · 2013-12-06 02:18 I moved the bug report to the correct place I already have a fix in my working copy but just noticed a regression. I will investigate when this regression was introduced before uploading the changes ---------------------------------------------------------------------- bill0287 · 2013-12-06 03:14 I added a new comment to the bug report. I have noticed some other incorrect behaviours that might be related to the same issue. ---------------------------------------------------------------------- BigChimp · 2013-12-06 10:04 Quote from: bill0287 on December 06, 2013, 12:32:56 amI never filed a bug before, so I took my best shot - thanks for looking it over and adding comments No problem - glad it's in and being looked at ---------------------------------------------------------------------- bill0287 · 2013-12-10 14:59 It says in the bugtracker that this is fixed. Is there a way I can get the fix and apply it to my 1.0.14 environment, or do I have to wait until 1.2 is released? I am new to this, so details are helpful. Thanks for such a quick response on this bug. ---------------------------------------------------------------------- engkin · 2013-12-11 18:12 Quote from: bill0287 on December 10, 2013, 03:59:56 pmI am new to this, so details are helpful. I'm not good at it either. Since no one answered you, here I'll try. Download these two files, and put them in their folders: First file: $(LazarusDir)/lcl/dbctrls.pp Second file: $(LazarusDir)/lcl/include/dblookup.inc Using your browser, you can see the changes here. ---------------------------------------------------------------------- bill0287 · 2013-12-11 20:51 I followed this and could not compile my project and got these errors: C:\lazarus\lcl\dbctrls.pp(265,15) Error: Forward declaration not solved "TDBText.Loaded;" C:\lazarus\lcl\dbctrls.pp(1151,15) Error: Forward declaration not solved "TDBCustomNavigator.SetImages(TCustomImageList);" C:\lazarus\lcl\dbctrls.pp(1156,15) Error: Forward declaration not solved "TDBCustomNavigator.ImageListChange(TObject);" C:\lazarus\lcl\dbctrls.pp(1682) Fatal: There were 3 errors compiling module, stopping ---------------------------------------------------------------------- engkin · 2013-12-11 21:19 dbctrls.pp was modified a lot, and other files are affected as well. For instance the first error needs a new copy of dbtext.inc, the other two errors need a new dbcustomnavigator.inc. After that it might or might not work. Return your previous files and do the changes manually. I don't think you want to download a new revision.  Edit: I believe these should be your original files: dbctrls.pp and dblookup.inc ---------------------------------------------------------------------- bill0287 · 2013-12-11 21:55 Thanks, but this is sounding too risky for me. I don't want to destabilize what I have. Also, is it safe to assume 1.2 will include all these fixes and is there a schedule to release 1.2? ---------------------------------------------------------------------- LuizAmérico · 2013-12-12 01:40 QuoteAlso, is it safe to assume 1.2 will include all these fixes and is there a schedule to release 1.2? The most recent fixes, no. You must use a snapshot or compile Lazarus from svn