Solved

Secondary Index

Posted on 1997-12-10
8
514 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
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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 

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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Working with hours 3 57
PHP preg_replace code convert to Delphi 14 55
firemonkey keyboard covers the controls 1 25
How to Get Images From Server using App Tethering 11 24
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…
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…
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…

770 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