Search for record with secondary index.

Posted on 1998-07-28
Last Modified: 2010-04-04

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);
     CustInfo.SetKey ;
     CustInfo.IndexName := 'ByCompany';
     CustInfo.FieldByName ('Company').asString := txtSearch.Text ;
     CustInfo.GotoNearest ;
Question by:Zoroaster
  • 2
  • 2

Expert Comment

ID: 1358810
The order should be like this instead:

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

Try also TTable.Locate...

Author Comment

ID: 1358811
Yes, works fine. Sometimes small details can count...
Thanks, Matvey.

Author Comment

ID: 1358812
Hey, fill in an answer. I cannot give you the points, because you wrote this as a comment.

Accepted Solution

Matvey earned 20 total points
ID: 1358813
Hi, was out all day so I was slow with responding.
-Glad I could help


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Reconfigure Delphi Install? 2 65
How to debug For loops? 3 63
When i run adoquery my application freezes 26 192
FMX and jaudiotracker playing memory stream 29 98
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question