Solved

Secondary Index

Posted on 1997-12-10
8
512 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
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 3

Expert Comment

by:Pegasus100397
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:koger
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 5

Expert Comment

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

0
 

Author Comment

by:koger
Comment Utility
No, don't work, I get a error

Table is not indexed. Index: Koger
0
 

Author Comment

by:koger
Comment Utility
Adjusted points to 100
0
 
LVL 3

Accepted Solution

by:
d4jaj1 earned 100 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
APK file name 7 63
proper way to parse url in delphi 2 131
delphi exception 7 58
How to renew a Delphi rad-studio licence? 5 33
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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

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

7 Experts available now in Live!

Get 1:1 Help Now