Solved

AddIndex

Posted on 1997-08-04
9
571 Views
Last Modified: 2010-04-04
I am using Delphi 1.0 for this project.

I am trying to add a new index to a DBaseIV DBF using:
   MyTable.Close;
   MyTable.AddIndex('TmpDx','Fld1;Fld2;Fld3;Fld4',
      [ixDescending]);
   MyTable.Open;
where Fld1,Fld2,Fld3 and Fld4 are field names in MyTable.

However I am repeatedly getting the error:
   EDBEngineError 'Invalid index descriptor'

Does anyone know how to fix this ?
   
0
Comment
Question by:jturpin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 

Expert Comment

by:rvaken
ID: 1340471
Dear sir,Please first check if there is a old Primary index. Or better just try to delete the primary index, then create a new one. Then you create your secondary index and fill in the IndexNames. Veryimportant is to make sure that you have created a valid KEY field in the first field of your table. When you set your primary index on this it will probably work.Good luck,Ronald
0
 
LVL 1

Author Comment

by:jturpin
ID: 1340472
I am creating the DBF on the fly, therfore I have not set a
primary index using the BDE. Is there another way of setting
a primary index ?

I tried:
   MyTable.AddIndex('PimeDX', 'Fld1',[ix Descending]);
and then later
   MyTable.Close;
   MyTable.AddIndex('TmpDx','Fld1;Fld2;Fld3;Fld4',
     [ixDescending]);
   MyTable.Open;

But I still get the same error !

0
 

Expert Comment

by:bsys
ID: 1340473
MyTable.AddIndex('IndPri', 'Number', [ixPrimary]);
MyTable.AddIndex('TmpDx','Fld1;Fld2;Fld3;Fld4',
                              [ixDescending]);

First make an Primary Index !!!!

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:jturpin
ID: 1340474
  .
   .
   .
   SetUpDBF fields etc
   with MyTable.IndexDefs do
   begin
      clear;
      Add('PrimDX','Tag',[ixPrimary]);  {Set primary index}
   end; {with}
   {I also tried MyTable.AddIndex('PrimDX','Tag',[ixPrimary]);}
   MyTable.CreateTable;
   .
   .
   .
   Bunch of processing
   .
   .
   .
   MyTable.AddIndex('TmpDX',
      'Fld1;Fld2;Fld3;Fld4',[ixDescending]);
   MyTable.IndexName:= 'TmpDX';


The primary index is created, but I still get the same
error: "Invalid Index Descriptor"
on the index with the four fields !

Note: If I use any one of the four fields on it's own,
then it works fine !


0
 

Expert Comment

by:bsys
ID: 1340475
Isn't this a dBase file creation problem, did you test it already with a Paradox file, I am using Paradox files and that is just going ok. I never tested it before!!!
0
 
LVL 1

Author Comment

by:jturpin
ID: 1340476
Apparently the answer is:
   MyTable.Addindex['SomeName', 'Multi-fields',
      [ixExpression, ixDescending]);
0
 
LVL 2

Expert Comment

by:icampbe1
ID: 1340477
Hi jturpin,

First of all, the concept of primary index does not apply do dBase files.  They have an active index (if any) PERIOD.  When you use the AddIndex routine, it wants the index name to be created, the Field name for that index (not fields) and then [ixDescending] if you want.

If you want the index to be made up of several fields, use the Database desktop to create a composite index: Field1+Field2 etc..  then use that one by its name in the program.  (Yes, you can do it programmatically as well, but I'm suggesting DB Desktop for speed so you can test what I'm saying).

Cheers,
Ian C.
0
 
LVL 1

Author Comment

by:jturpin
ID: 1340478
Thanks ICampbel.

The answer is in my comment, posted before your answer.
However there is no way of removing the question if
I answered it myself.

In order to create a multi-field index, I have to use
ixExpression. Without it the program will crash.

It would have been better if I could have returned my
own expression, instead of a bunch of field names.

Do you know if I can do that ?

e.g.  MyTable.AddIndex('TmpDX',FncX,[ixExpression]);
where FncX : String;

John.
0
 
LVL 2

Accepted Solution

by:
icampbe1 earned 100 total points
ID: 1340479
Hi again John,

I'm not sure if you want a comment or answer here.  Let me try...

If you are going to build a composite index like that, beware...  make sure that the fields are all StringFields.  If they are Integer for example you wont get what you think.   With String fields, A firstnameField + LastnameField works like 'Ian' + 'Campbell' is IanCampell.   With Integer fields, 5 in one field and 8 in another with yield a single index of 13... so it obviously wont sort like you expect.  (When they say 'expression', I guess they really mean it.)

Something you can do though... dBase lets you create filtered indexes.  These are kinda neat, because you can have lots of them defined and use them at will.  If the function you wanted to use would have resulted in some kind of filter like that, then its a good fit.

Don't worry about rejecting the answer, sometimes the person writing a question and the person answering answering it, aren't reading from exactly the same page.  I have had a lot of experience with tables, dBase, Paradox and the DBE though.

Hope this helps,
Ian C.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month5 days, 5 hours left to enroll

635 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