Link to home
Start Free TrialLog in
Avatar of Zoroaster
ZoroasterFlag for Belgium

asked on

Search for record with secondary index.


I use this piece of code (from the Sams book) to search for a record in a db and I get the error message that the dataset is not in edit or insert mode (suppose this is because I use the SetKey command).
Can anybody tell me what's going wrong?



procedure TForm1.btnSearchClick(Sender: TObject);
begin
     CustInfo.SetKey ;
     CustInfo.IndexName := 'ByCompany';
     CustInfo.FieldByName ('Company').asString := txtSearch.Text ;
     CustInfo.GotoNearest ;
end;
Avatar of Matvey
Matvey

The order should be like this instead:


         CustInfo.IndexName := 'ByCompany';
         CustInfo.SetKey ;
         CustInfo.FieldByName ('Company').asString := txtSearch.Text ;
         CustInfo.GotoNearest ;

Try also TTable.Locate...
Avatar of Zoroaster

ASKER

Yes, works fine. Sometimes small details can count...
Thanks, Matvey.
Hey, fill in an answer. I cannot give you the points, because you wrote this as a comment.
ASKER CERTIFIED SOLUTION
Avatar of Matvey
Matvey

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial