case insensitive Lookup field in delphi

Home Forums kbmMemTable case insensitive Lookup field in delphi

Viewing 3 reply threads
  • Author
    Posts
    • #56995
      mikakoistinen
      Participant

      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?

       

    • #57102
      kimbomadsen
      Keymaster

      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

    • #57316
      Mika Koistinen
      Participant

      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.

    • #57317
      Mika Koistinen
      Participant

      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;
Viewing 3 reply threads
  • You must be logged in to reply to this topic.