Kbase P22105: How to create a case-sensitive combo-box ?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  01/04/2003 |
|
Status: Unverified
GOAL:
How to create a case-sensitive combo-box ?
GOAL:
How to make a combo-box case-sensitive ?
FIX:
Since a combo-box widget cannot simply be defined as case sensitive, case-sensitive behavior must be handled another way.
To set the displayed value in a way that respects case-sensitivity use the following procedure:
PROCEDURE CaseSensitiveCombo :
DEFINE INPUT PARAMETER hWidget AS HANDLE NO-UNDO.
DEFINE INPUT PARAMETER cKey AS CHARACTER NO-UNDO CASE-SENSITIVE.
DEFINE VARIABLE iCounter AS INTEGER NO-UNDO INITIAL 1.
DEFINE VARIABLE lInputOk AS LOGICAL NO-UNDO.
/* Check if procedure can be run */
IF CAN-QUERY(hWidget,"LIST-ITEM-PAIRS") THEN RETURN ERROR "Doesn't work with LIST-ITEM-PAIRS".
/* Check if input matches a valid entry to prevent infinite loops */
DO iCounter = 1 TO NUM-ENTRIES(hWidget:LIST-ITEMS, hWidget:DELIMITER):
lInputOk = lInputOk OR ENTRY(iCounter,hWidget:LIST-ITEMS,hWidget:DELIMITER) BEGINS cKey.
END.
IF NOT lInputOk THEN RETURN.
/* Set search flag on */
hWidget:PRIVATE-DATA = hWidget:PRIVATE-DATA + ",searching".
/* From here, we'll be simulating keystrokes until the widget has a value we
want it to have */
/* First keystroke. Without this, the combo would get "stuck"*/
APPLY cKey TO hWidget.
/* Now keep repeating keystrokes until we found the first value we want, using
BEGINS operator which is case-sensitive because cKey is case-sensitive. */
DO WHILE NOT hWidget:INPUT-VALUE BEGINS cKey:
APPLY cKey TO hWidget.
END.
/* And search flag off */
hWidget:PRIVATE-DATA = REPLACE(hWidget:PRIVATE-DATA,",searching","").
END PROCEDURE.
To set the value, use the following statement:
RUN CaseSensitiveCombo(combo-box handle, First letter of value).
Any "APPLY keyboard-event TO combo-box" statement should also be replaced with a call to this procedure.
In addition, to ensure user input also respects case-sensitivity, add the following trigger to the combo-box:
ON ANY-PRINTABLE OF combo-box IN FRAME DEFAULT-FRAME /* Example */
DO:
/* Instead of handling any-printable as normal, start case-sensitive search.
If already searching, let the event finish as normal, the search depends on this. */
IF LOOKUP("searching",SELF:PRIVATE-DATA) = 0 THEN DO:
RUN CaseSensitiveCombo (SELF:HANDLE,LAST-EVENT:LABEL).
RETURN NO-APPLY.
END.
END.
The PRIVATE-DATA attribute of the combo-box should also be assigned something (anything will do, even an empty string) during initialization of the procedure (for static combo-boxes) or the widget (for dynamic ones), otherwise this trigger will fail to work as expected.