An alternative solution is to use TComboBox rather than TDBLookupComboBox. Use TDictionary to define a simple search in memory.
type
TMyForm = class(TForm)
MyComboBox: TComboBox;
MyDataset: TSimpleDataSet;
procedure MyComboBoxChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
ComboLookup: TDictionary<string, Char>;
end;
implementation
{$R *.dfm}
procedure TMyForm.FormCreate(Sender: TObject);
var
Key: string;
begin
ComboLookup := TDictionary<string, Char>.Create;
ComboLookup.Add('Drivers License', 'A');
ComboLookup.Add('Passport', 'B');
ComboLookup.Add('Library Card', 'C');
for Key in ComboLookup.Keys do
begin
MyComboBox.Items.Add(Key);
end;
end;
procedure TMyForm.MyComboBoxChange(Sender: TObject);
begin
// This may be wrong didn't bother to look
//up the correct way to change a field value in code.
MyDataset.Fields.FieldByName('IDCard').AsString := ComboLookup[MyComboBox.Text];
end;
You can use TComboBox.Items.AddObject instead of a separate lookup table, but you need to create a wrapper class for storing char as a TObject or use Chr to convert it to an integer and then pass it to TObject but, in my opinion, it's easier.
anon
source
share