Board index » delphi » TTable.AddIndex Works for Dbase, not for Paradox

TTable.AddIndex Works for Dbase, not for Paradox

Perhaps this is a better group to post this problem.

I set up a little database viewer that allows the user to click on the
title of a TDBGrid Column, and that will cause the index to change to
that column (ie, sorted by the chosen column).

If there is no index for the column, then I must create one.  In the
TDBGrid 'OnTitleClick' event, I added the following code:

procedure TForm1.DBGrid1TitleClick(Column: TColumn);
var
  FieldName, IdxName : string;
  GotValidIndex : boolean;
  i : integer;

begin
  GotValidIndex := false;
  FieldName := Column.FieldName;  // save field name - goes away when
table closed
  // see if we already have an index for this field
  for i := 0 to Table1.IndexDefs.Count - 1 do begin  // see if the field

is first in the key definition
    if (Pos(FieldName,Table1.IndexDefs.Items[i].Fields) = 1) then begin
      Table1.IndexName := Table1.IndexDefs.Items[i].Name;
      GotValidIndex := true;
      break;
      end; // if field found
    end; // for all index fields

  // if no index was found, then create a temporary index
  if not GotValidIndex then begin
    Table1.Close;
    Table1.Exclusive := true;
    Table1.Open;
    IdxName := 'TMPI' + FieldName;

// error occurs here
    Table1.AddIndex(IdxName,FieldName,[]);  // <<--- blows up here !!

    Table1.IndexName := IdxName;
    Table1.IndexDefs.Update;
    Table1.Close;
    Table1.Exclusive := false;
    Table1.Open;
    end;
end;

Now, I used the Delphi DB Demo databases here.  If I select ANIMALS.DBF
(a Dbase database), this works just fine. However, when I select
BIOLIFE.DB (a Paradox database), this routine generates the exception:

Thinking that perhaps I was generating an invalid file name by
concatenating
field names, I substituted a fixed file name as in:

IdxName := 'TempIdx';

This still results in the error message as I have shown below.

W

Invalid Index/Tag Name
Index does not exist
Index TMPIxxxx

where xxxx is the FieldName in question.

Table is not active at design time, it is opened at the form create.
Can anyone tell me why this works with DBase but not Paradox?

Thank you very many.

--
Wayne Herbert
Manager, Computer Products
Key Maps, Inc.
1411 West Alabama
Houston, TX  77006

Vox:  713.522.7949
Fax:  713.521.3202
Email:  wherb...@rice.edu

"Why is it only drug dealers and software developers call their clients
'users'?"

--
Wayne Herbert
Manager, Computer Products
Key Maps, Inc.
1411 West Alabama
Houston, TX  77006

Vox:  713.522.7949
Fax:  713.521.3202
Email:  wherb...@rice.edu

"Why is it only drug dealers and software developers call their clients
'users'?"

 

Re:TTable.AddIndex Works for Dbase, not for Paradox


Quote
>// error occurs here
>    Table1.AddIndex(IdxName,FieldName,[]);  // <<--- blows up here !!

for Paradox tables single field case insensative indexes must have the
same name as the field they are indexing.

Try
Table1.AddIndex(IdxName,FieldName,[ixCaseInsensative]);

--
Brian Bushay (TeamB)
Bbus...@DataGuidance.com

Re:TTable.AddIndex Works for Dbase, not for Paradox


Quote
Brian Bushay TeamB wrote:

> >// error occurs here
> >    Table1.AddIndex(IdxName,FieldName,[]);  // <<--- blows up here !!

> for Paradox tables single field case insensative indexes must have the
> same name as the field they are indexing.

> Try
> Table1.AddIndex(IdxName,FieldName,[ixCaseInsensative]);

> --
> Brian Bushay (TeamB)
> Bbus...@DataGuidance.com

I have the same error.  However, my reading of the Database Desktop
indicates that Case Sensitive indexes have the same name as the field.  
Anyway I've tried:

  Table1.AddIndex('TPName','TpName',[ixCaseInsensitive]);
or
  Table1.AddIndex('TPName','TpName',[]);

and they both crash with "Table is not indexed"

What gives?  Thanks for your help!

Bob

Re:TTable.AddIndex Works for Dbase, not for Paradox


I entered this thread in the middle but thought I would try to help:
Do you have a primary index for the table??  In paradox,  there must be a
Primary Index already exisiting I believe and then you can use addIndex to
create a secondary Index.  Although, I have had problems with AddIndex in
Delphi 1 even when I've obeyed that rule and the naming rule.  I have seen
identical code work for one table and not another in Delphi 1.

Quote
Bob Yee wrote in message <353F42E1.4...@worldnet.att.net>...
>Brian Bushay TeamB wrote:

>> >// error occurs here
>> >    Table1.AddIndex(IdxName,FieldName,[]);  // <<--- blows up here !!

>> for Paradox tables single field case insensative indexes must have the
>> same name as the field they are indexing.

>> Try
>> Table1.AddIndex(IdxName,FieldName,[ixCaseInsensative]);

>> --
>> Brian Bushay (TeamB)
>> Bbus...@DataGuidance.com

>I have the same error.  However, my reading of the Database Desktop
>indicates that Case Sensitive indexes have the same name as the field.
>Anyway I've tried:

>  Table1.AddIndex('TPName','TpName',[ixCaseInsensitive]);
>or
>  Table1.AddIndex('TPName','TpName',[]);

>and they both crash with "Table is not indexed"

>What gives?  Thanks for your help!

>Bob

Re:TTable.AddIndex Works for Dbase, not for Paradox


Quote
>I have the same error.  However, my reading of the Database Desktop
>indicates that Case Sensitive indexes have the same name as the field.  
>Anyway I've tried:

You are correct I should have typed caseSensative

Quote

>  Table1.AddIndex('TPName','TpName',[ixCaseInsensitive]);
>or
>  Table1.AddIndex('TPName','TpName',[]);

>and they both crash with "Table is not indexed"

This error indicates that your table must have a primary index to add
a maintained secondary index.

--
Brian Bushay (TeamB)
Bbus...@DataGuidance.com

Re:TTable.AddIndex Works for Dbase, not for Paradox


Yes, the Paradox file does have a primary key specified... a multiple column
key, actually, in my file(s), while I believe the BIOLIFE.DB has a single
column key.  I've played around some more, still cannot get it to work,
although I have had different error messages returned when I ran the offending
code as a snippet.

I've submitted the problem and my doc to Borland's bug report page... although
I feel like I've just tossed it into a black hole and have watched it get
sucked into the event horizon... whoosh!

Quote
Art Begun wrote:
> I entered this thread in the middle but thought I would try to help:
> Do you have a primary index for the table??  In paradox,  there must be a
> Primary Index already exisiting I believe and then you can use addIndex to
> create a secondary Index.  Although, I have had problems with AddIndex in
> Delphi 1 even when I've obeyed that rule and the naming rule.  I have seen
> identical code work for one table and not another in Delphi 1.

> Bob Yee wrote in message <353F42E1.4...@worldnet.att.net>...
> >Brian Bushay TeamB wrote:

> >> >// error occurs here
> >> >    Table1.AddIndex(IdxName,FieldName,[]);  // <<--- blows up here !!

> >> for Paradox tables single field case insensative indexes must have the
> >> same name as the field they are indexing.

> >> Try
> >> Table1.AddIndex(IdxName,FieldName,[ixCaseInsensative]);

> >> --
> >> Brian Bushay (TeamB)
> >> Bbus...@DataGuidance.com

> >I have the same error.  However, my reading of the Database Desktop
> >indicates that Case Sensitive indexes have the same name as the field.
> >Anyway I've tried:

> >  Table1.AddIndex('TPName','TpName',[ixCaseInsensitive]);
> >or
> >  Table1.AddIndex('TPName','TpName',[]);

> >and they both crash with "Table is not indexed"

> >What gives?  Thanks for your help!

> >Bob

--
Wayne Herbert
Manager, Computer Products
Key Maps, Inc.
1411 West Alabama
Houston, TX  77006

Vox:  713.522.7949
Fax:  713.521.3202
Email:  wherb...@rice.edu

"Why is it only drug dealers and software developers call their clients
'users'?"

Re:TTable.AddIndex Works for Dbase, not for Paradox


Quote
Brian Bushay TeamB wrote:

> >I have the same error.  However, my reading of the Database Desktop
> >indicates that Case Sensitive indexes have the same name as the field.
> >Anyway I've tried:
> You are correct I should have typed caseSensative

> >  Table1.AddIndex('TPName','TpName',[ixCaseInsensitive]);
> >or
> >  Table1.AddIndex('TPName','TpName',[]);

> >and they both crash with "Table is not indexed"

> This error indicates that your table must have a primary index to add
> a maintained secondary index.

> --
> Brian Bushay (TeamB)
> Bbus...@DataGuidance.com

Thanks, that was my problem.  Set up a primary index and all is well
now.  Thanks for the help.

Other Threads