Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

AddIndex

Posted on 1997-08-04
9
Medium Priority
?
578 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
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 200 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

Technology Partners: 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!

Question has a verified solution.

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

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

877 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