Board index » delphi » D1:Secondary Indexes and Searching

D1:Secondary Indexes and Searching

This is a newbie question but I hope the guru's can help. I have a table,
call it 'Buildings' that sort of looks like;

BuildingID
BuildingName
Address
City
Contact
Month Due

BuildingID and BuildingName are the primary indexes in this Paradox5 table.
What I want to do is search through the database looking for a particular
'Month Due'. When I tried to do this I get all kinds of exceptions.
Remember, I'm a newbie so please bear with me but the code looks like;

         Buildings.AddIndex('BWOIndex', 'CustID;BuildingID;Month Due',
[ixUnique]);
         Buildings.IndexName := 'BWOIndex'; { Build Work orders on this
index name}
         Buildings.SetKey;
         Buildings.FieldByName('Month Due').AsString :=
WOGenerateDlg.WOGenerateMonthCombo.SelText;
         Buildings.GotoKey;

I've tried a few variations of the above however I found nothing that works.
If someone can give me some pointers I would be extremely greatful.
Specifically, I was wondering;

1) How to build a secondary Index without getting exceptions
2) How to search for a non-indexed field
3) How to retrieve data from the location were the cursor is (ie: once I
have found the record)

I have some master-detail question, however leave this for another time
since it's not much use if I can't even find the records I'm looking for.
Again, any and all help appreciated.

--
K Fisk (mailto:kf...@awinc.com)
"Gotta remember to unplug the phone"

 

Re:D1:Secondary Indexes and Searching


Quote
In article <64p1ci$53...@noc.van.hookup.net> "Kevin Fisk" <kf...@awinc.com> writes:
>This is a newbie question but I hope the guru's can help. I have a table,
>call it 'Buildings' that sort of looks like;
>BuildingID
>BuildingName
>Address
>City
>Contact
>Month Due
>BuildingID and BuildingName are the primary indexes in this Paradox5 table.
>What I want to do is search through the database looking for a particular
>'Month Due'. When I tried to do this I get all kinds of exceptions.
>Remember, I'm a newbie so please bear with me but the code looks like;
>         Buildings.AddIndex('BWOIndex', 'CustID;BuildingID;Month Due',
>[ixUnique]);
>         Buildings.IndexName := 'BWOIndex'; { Build Work orders on this
>index name}
>         Buildings.SetKey;
>         Buildings.FieldByName('Month Due').AsString :=
>WOGenerateDlg.WOGenerateMonthCombo.SelText;
>         Buildings.GotoKey;
>I've tried a few variations of the above however I found nothing that works.
>If someone can give me some pointers I would be extremely greatful.
>Specifically, I was wondering;
>1) How to build a secondary Index without getting exceptions
>2) How to search for a non-indexed field
>3) How to retrieve data from the location were the cursor is (ie: once I
>have found the record)
>I have some master-detail question, however leave this for another time
>since it's not much use if I can't even find the records I'm looking for.
>Again, any and all help appreciated.

To start with, Kevin, I would set up the secondary indexes ahead of time and
leave them there.  If you are going to use an index to do the search then you
don't want to subject the user to rebuilding that index constantly.  And, if
the data has only a few hundred or maybe a thousand records in it,
particularly if they're not large records, you might dispense with the index
entirely and find that it's "just as good."

Next, in your example, the index does you no good at all because you have done
a unique-index on three fields but you search on only one; the third.  I
presume that you simply omitted the other two from your example...

Last, you can search on any field with a simple "Find," omitting the use of
the index and GotoKey.  Once you have found the record you can then retrieve
the values using field-objects or FieldByName.

Other Threads