Solved

Secondary Index

Posted on 1997-12-10
8
518 Views
Last Modified: 2010-04-04
How do I create a secondary index at runtime, I have checked addindex, but I get an error saying that I can't create it, what do I have to be aware of? Could anybody send me a example that works?
0
Comment
Question by:koger
[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
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 3

Expert Comment

by:Pegasus100397
ID: 1353294
Koger, please, what database are you using? Oracle is different from MS SQL Server is different from dBase is different from Sybase, etc, etc, etc. Is it a REAL database like MS SQL Server or a database-wanna-be like Paradox or dBase?

0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1353295
It's just a hunch, but for the AddIndex options paramater use [ixCaseInsensitive] without any other options.
E.g.  MyTable.AddIndex('NewIx', 'CustNum', [ixCaseInsensitive]);

JB
0
 
LVL 3

Expert Comment

by:d4jaj1
ID: 1353296
There is a quirk with index names:

 if IndexName = Fieldname then ixCaseSensitive is reqd (the default)
 if IndexName <> Fieldname then ixCaseInsensitive is reqd

Thus you need:

  table.AddIndex('cusname', 'name', [ixCaseInsensitive]);

or

  table.AddIndex('name', 'name', []);

Any questions, please add a comment.

Good Luck!
Jay
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

Author Comment

by:koger
ID: 1353297
I forgot to said that the database is paradox, here comes the code that I write:

procedure TForm1.Button1Click(Sender: TObject);
begin
  with Form2.Table1 do
  begin
    with FieldDefs do
    begin
      Clear;
      Add('Name:', ftString, 50, False);
      //and alot more
    end;
    CreateTable;
    Form2.Table1.Open;
  end;
  Form2.Show;
end;



procedure TForm2.Button1Click(Sender: TObject);
begin
  Table1.Refresh;
// is this ok to save the table?
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
  Table1.AddIndex('koger', 'Name:', []);
end;

0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1353298
Try this in Button2Click:
Table1.AddIndex('koger', 'Name:', [ixCaseInsensitive]);

0
 

Author Comment

by:koger
ID: 1353299
No, don't work, I get a error

Table is not indexed. Index: Koger
0
 

Author Comment

by:koger
ID: 1353300
Adjusted points to 100
0
 
LVL 3

Accepted Solution

by:
d4jaj1 earned 100 total points
ID: 1353301
Sorry, I've been on vacation for a while and didn't see any of your comments.  All of the code above will work, but only in certain situations.  I'm willing to work with you until we get it solved.

At first sight, it appears the problem in your original statement (Table1.AddIndex('koger', 'Name:', []);)is the missing Index option ixcaseinsensitive.  In JimBob's solution, you can remove the Colon (:).  If you are trying to assign an index to the field Kroger, you MUST set it as the Primary Index FIRST.  The reason you are getting the error is you can't set a Secondary Index before you set a Primary Index. So try this,

Add('Kroger', 'Name', [ixPrimary, ixUnique]);

The code below may be a little better for you since it creates the table and its indexes all at the same time.

 with Table1 do
  begin
   Active := False;
   DatabaseName := 'DBDemo';
   TableName := 'Your_Table_Name';
   TableType := ttParadox;
   with FieldDefs do
    begin
     Clear;
     Add('Name', ftString, 30, False);
    end;
   with IndexDefs do
    begin
    Clear;
    Add('Name', 'Name', [ixPrimary, ixUnique]);  //or 'Kroger' then 'Name'
   end;
  end;
  table1.CreateTable;
 end;
end;

Any more questions, please add a comment - I'm sure we can work it out.

Good Luck!
Jay
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses
Course of the Month9 days, 8 hours left to enroll

624 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