Solved

AddIndex

Posted on 1997-08-04
9
549 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

12 Experts available now in Live!

Get 1:1 Help Now