Link to home
Start Free TrialLog in
Avatar of koger
koger

asked on

Secondary Index

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?
Avatar of Pegasus100397
Pegasus100397

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?

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
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
Avatar of koger

ASKER

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;

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

Avatar of koger

ASKER

No, don't work, I get a error

Table is not indexed. Index: Koger
Avatar of koger

ASKER

Adjusted points to 100
ASKER CERTIFIED SOLUTION
Avatar of d4jaj1
d4jaj1

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial