Solved

AddIndex

Posted on 1997-08-04
9
564 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
Industry Leaders: 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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
Mobile Keyboard covers the display of the TMemo 3 115
Press three keys together and trigger a function 3 75
Dynamically Created Query 3 80
Posting a string with PostMessage 23 48
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…

739 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