Subject Re: [IBO] IB_Combox and IB_Grid again
Author Geoff Worboys
> In IBC_ComboBox.IMP , line 421,
> Sometimes the aVal parameter pass items value or itemvalues, cause
> the display text in grid empty, so i correct the source code for
> proper display text .
>
> function TIB_CustomComboBox.IBG_TranslateText(AVal: string): string;
> begin
> // Result := Items.Strings[ ItemValues.IndexOf( AVal ) ];
> Result := aVal;
> if Items.IndexOf( aVal ) = -1 then
> Result := Items.Strings[ ItemValues.IndexOf( AVal ) ];
> end;
>
> Is this correct?

The idea is that this function is called to translate an actual stored
value into a value appropriate for display to the user.

Looking at the original code I believe you are correct that it is
inappropriate.

After discovering similar problems with my Enh combobox I think that
we may need to check the combobox style - and whether or not the user
has actually defined a separate set of ItemValues. So possibly the
code should be...

function TIB_CustomComboBox.IBG_TranslateText(AVal: string): string;
var
tmpIndex: integer;
begin
Result := AVal;
// With csDropDown style any value is acceptable and so
// ItemValues is ignored and no translation performed.
if Style = csDropDownList then
begin
// let blank values pass straight through
if Length(AVal) > 0 then
begin
// if separate itemvalues provided ensure given
// value exists in that list.
if ItemValues.Count > 0 then
begin
// If given value not found in ItemValues then
// return blank, otherwise return corresponding
// display value from Items list.
tmpIndex := ItemValues.IndexOf( AVal );
if tmpIndex >= 0 then
Result := Items.Strings[ tmpIndex ]
else
Result := '';
end
else // if no separate ItemValues defined
begin
// If given value not found in Items list then
// return blank. Otherwise the item will be
// returned directly (already assigned to result)
tmpIndex := Items.IndexOf( AVal );
if tmpIndex < 0 then
Result := '';
end;
end;
end;
end;


Does this appear to achieve what you want? Would you be able to test
this on both csDropDown and csDropDownList boxes? (I dont use
TIB_ComboBox myself and have nothing setup to test with.)

I think the code is more explicit and should allow csDropDown style
boxes to work as expected (I suspect there must be problems at the
moment).

AFAICT letting blank values pass straight through should be a correct.
If any ItemValues are defined it should be a complete set of permitted
values (in a csDropDownList style box) and so you should only get a
display when a non-blank value is matched. Without any ItemValues
list the same rule applies to the Items list, the given value must be
found.

Thoughts?

Geoff Worboys
Telesis Computing