Solved

AddIndex

Posted on 1997-08-04
9
553 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now