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;
ZoroasterAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
MatveyConnect With a Mentor Commented:
Hi, was out all day so I was slow with responding.
-Glad I could help

0
 
MatveyCommented:
The order should be like this instead:


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

Try also TTable.Locate...
0
 
ZoroasterAuthor Commented:
Yes, works fine. Sometimes small details can count...
Thanks, Matvey.
0
 
ZoroasterAuthor Commented:
Hey, fill in an answer. I cannot give you the points, because you wrote this as a comment.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.