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?
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
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
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
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;
procedure TForm1.Button1Click(Sender
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
begin
Table1.Refresh;
// is this ok to save the table?
end;
procedure TForm2.Button2Click(Sender
begin
Table1.AddIndex('koger', 'Name:', []);
end;
Try this in Button2Click:
Table1.AddIndex('koger', 'Name:', [ixCaseInsensitive]);
Table1.AddIndex('koger', 'Name:', [ixCaseInsensitive]);
ASKER
No, don't work, I get a error
Table is not indexed. Index: Koger
Table is not indexed. Index: Koger
ASKER
Adjusted points to 100
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.