Solved

Secondary Index

Posted on 1997-12-10
8
516 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

830 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