TwwDBLookupComboBox -

1,012 views
Skip to first unread message

Scott Nemetz

unread,
Oct 3, 2013, 12:17:06 PM10/3/13
to woll2woll...@googlegroups.com
I have a perplexing problem that we cannot figure out for the life of us and I'm hoping you can help.  I am using Delphi XE3 and InfoPower Studio 2013.

I have a TwwDBLookupComboBox that allows the user to select the sex of an individual.  My lookup field is set to the description (Female), but the list shows description (Female) and code (F) (two different columns).  I am also using the NotInTheList event in case the user wants to enter the code value (F) instead of the description value (Female).  The NotInTheList is not really a problem with this example, but I do have several other fields where the code is 01 or 02 and the description is Gang or Individual, something like that, but I digress.  The problem that I am finding is that whenever I try to select "M" or "MALE", it always selects "FEMALE".  I have found that since "MALE" is contained in "FEMALE" that this is causing the problem.  I updated my code table, for testing purposes, changing the word female to "FEWALE" and everything worked perfectly.  So, I'm not sure if this is a bug or if there is something I'm doing wrong and I'm hoping you can help.  

It looks as if when the field is searched, it does a LIKE type search to find a corresponding match.  So, for example, when the user types "M", it finds "M" in Female and then selects it, never making it to the next row where Male resides.


Properties:

LookupField:  CodeDescription
LookupTable:  DataSetLookupCode
Selected: CodeDescription 30 CodeDescription
SeqSearchOptions: ssoEnabled
ShowMatchText: True
Style: csDropDownList
UseTFields: True


Lookup Values

CodeDescription Code
FEMALE F
MALE M
UNKNOWN U

Ric Hupalo

unread,
Oct 4, 2013, 8:10:25 PM10/4/13
to woll2woll...@googlegroups.com
I'm just another user, but I would do things differently. I would set the lookup field to Code, not Description. The description value is present to help the user find the correct code. Typically you would want to assign the Code value from the lookup table to the Datafield of the DataSource referenced by the lookupcombobox.
 
Your lookup table in your relational database should have an index on the code field. The style scDropDownList does not allow them to edit the list values or add values, this is what I generally want. I usually don't use the TFields. The F1 context help is excellent in InfoPower, reading-up a bit about this component may be helpful.
 
Good Luck,
Ric

Roy Woll

unread,
Oct 4, 2013, 10:30:42 PM10/4/13
to woll2woll...@googlegroups.com
I'm not clear on why you are experiencing searching in the middle of the field value. Try overriding the search, and use the OnPerformCustomSearch event to force the searching to be based on your own code as follows...
procedure TLookupForm.wwDBLookupCombo2PerformCustomSearch(Sender: TObject;
  LookupTable: TDataSet; SearchField, SearchValue: string;
  PerformLookup: Boolean; var Found: Boolean);
begin
  if not lookuptable.active then exit;
  if performlookup then
    found:= lookuptable.Locate(searchfield, searchvalue, [])
  else
    found:= lookuptable.Locate(searchfield, searchvalue, 
[TLocateOption.loPartialKey]);

Scott Nemetz

unread,
Mar 3, 2014, 1:42:57 PM3/3/14
to woll2woll...@googlegroups.com
Good Afternoon Roy,

I have found the problem that I am having with regards to not being able to select the correct values from the lookup table.  It appears to be when you place a filter on the table.  So, here is what I have:

1.  A lookup table with the following values:

DESCRIPTION          CODE
Female                          F
Male                              M
Unknown                       U

Unless I physically type the word "Male", Female will always be select when filtering the table.

Scenario:

I have a large table filled with lookup values with the following columns:
CodeType
Code
Description

1.  At runtime, when the application is started, I read all of the codes into my dataset so to limit the number of SQL queries I perform when using the lookup comboboxes.  
2.  Using the OnEnter event, I run the following code:

           with DataSetLookup do begin
             Filter     := 'CodeType = ' + QuotedStr('Sex');
             Filtered := True;
           end;

     This limits the results for the Sex field to only M (Male), F (Female), and U (Unknown).

If I remove the filter, I can type M and get Male, or F and get Female.  If the filter is in place, only Female will be selected.

Thoughts?

Roy Woll

unread,
Mar 4, 2014, 4:00:08 PM3/4/14
to woll2woll...@googlegroups.com
I'm not clear on the exact nature of your problem. It seems that you are saying that the incremental searching is not working on the control when you have the dataset as filtered.  Incremental searching uses the active index so if are searching on a non-indexed field then you could possibly have incremental searching issues. Have you tried troubleshooing by using the OnPerformCustomSearch event as mentioned in my previous message. By doing so, you can see if the locate is failing.

-Roy

Scott Nemetz

unread,
Apr 23, 2014, 5:39:24 PM4/23/14
to woll2woll...@googlegroups.com
Good Afternoon Roy,

I am still struggling with this problem which appears to be related to the DataSet Filters.  I have made a sample program for you to test to see if there is something we are missing.  Notice if you start typing in a dblookupcombo the records are never highlighted and selected, which forces the user to use the mouse to select from the drop down.

If you could, please take a look and see if you can add your two cents worth.

Thanks,

Scott

example.zip

Scott Nemetz

unread,
Apr 24, 2014, 1:08:44 PM4/24/14
to woll2woll...@googlegroups.com
Good Morning Roy,

Sorry for too many emails.  I was looking at the zip file and I forgot to include the table with the data.  This is a new project including the table.  We have isolated the problem to "filtering" the dataset.  However, when running a new query (i.e.: SELECT * FROM AL_Codes WHERE CodeCategoryID = 'Race') the lookup combos work perfectly.

I know you are busy, but if you can take a look as soon as possible, I would appreciate it.  

Thanks,
Scott


example.zip

Roy Woll

unread,
Apr 24, 2014, 4:37:29 PM4/24/14
to woll2woll...@googlegroups.com
Hi Scott,

I took a look at your project first with Delphi XE5, and did not experience any problems. I then went to XE3 and was able to reproduce your problem. I then studied our code and it has not changed, so something is different with ADO between XE3 and XE5. In particular after investigating, it appears that the locate method of the TADODataSet does not work in XE3.  To verify this, I put the following code in a TSpeedButton after moving focus to the race field

 if lookup.Locate('Code', 'B',  [loPartialKey, loCaseInsensitive]) then
 begin
    showmessage(lookup.FieldByName('Code').asstring);
 end;

The message displayed for me is 'W', not 'B', so clearly the locate method is not moving the dataset position when it is filtered. There is not much our code can do as the underlying locate method seems broken in XE3 with TADODataSet; 

Unfortunately, you will need to find another way for your lookups or move to XE5 or XE6, for instance, filling a TwwComboBox (mapped list)

-Roy

Scott Nemetz

unread,
Apr 24, 2014, 5:12:27 PM4/24/14
to woll2woll...@googlegroups.com
Thanks bunches Roy.  Not exactly what we wanted to hear, but I totally understand.  We'll probably upgrade to XE5.

Scott
Reply all
Reply to author
Forward
0 new messages