- This topic has 3 replies, 3 voices, and was last updated 2 years, 5 months ago by .
Viewing 3 reply threads
Viewing 3 reply threads
- You must be logged in to reply to this topic.
Home › Forums › kbmMemTable › case insensitive Lookup field in delphi
Hi,
I’m trying to create lookupdataset using tKbmMemtable, data is provided from query and loaded LoadFromDataSet( q, [ mtcpoStructure, mtcpoProperties ] ). after that I define IndexField Memtable.indexFieldNames := ‘mykeyfield:C’;
But my issue is that lookup is not caseinsensitive. Delphi calls it using FLookupDataSet.Lookup(FLookupKeyFields,FDataSet.FieldValues[FKeyFields], FLookupResultField).
Should index definition help, or is there any other solution?
Hi,
You need to define an index first and then switch to it.
Use AddIndex. Then set IndexName:=your defined indexname.
Then you can make case insensitive lookups.
/Kim
Thanks For this.
Actually at that point primary customer using that updated data to match case. But now we got two more cases.
My code is like this
fProdLookup := tKbmMemTable.create(self);
q.sql.Text := 'select number,name from products';
q.UniDirectional := true;
q.open;
fProdlookup.LoadFromDataSet(q, [mtcpoStructure,mtcpoProperties]);
fProdLookup.addIndex('iNumber','number',[ixCaseInsensitive]);
fProdLookup.indexName := 'iNumber';
But still case casesensitive lookups.
Actually solution was more simple than I tought.
TCaseInsentiviveKbmMemtable = class (TkbmMemTable)
function Lookup(const KeyFields: string; const KeyValues: Variant; const ResultFields: string): Variant; overload; override;
end;
...
function TCaseInsentiviveKbmMemtable.Lookup(const KeyFields: string; const KeyValues: Variant;
const ResultFields: string): Variant;
var
options: TLocateOptions;
begin
options := [loCaseInsensitive];
Result:=Lookup(KeyFields,KeyValues,ResultFields,options);
end;