I have been working with Delphi for the past 2 years, however, up until a few weeks ago I have avoided using any of Delphi's database components. I simply never had any need for a database.
Now that I have a need to create a database, I have chosen Delphi,...of course. However, I am puzzled with how indexes work with a DBF table created with Database Desktop 7, and used under Delphi 3.
I have a TDBGrid, TTable and TDataSource component on my main form. Data is entered into the grid/table programmatically, rather than manually typing data into the grid. E.g.,
Table1.FieldByName('CONFIRMED').AsBoolean := True;
I created two indexes (LAST.NDX and EMAIL.NDX) in Database Desktop 7. After the indexes are created in Database Desktop, this is where I get confused. I understand what an index is...this is not the problem. The problem is
regarding the TTable's IndexFiles, IndexFieldNames, and IndexName properties. I have a problem understanding the difference between these properties. When are they used? What do they do?
I have been assigning the IndexFiles property to "LAST.NDX" and "EMAIL.NDX" at design time using the Object Inspector. However, as I run my application, and records are added to the database, I start to notice something very odd. Records that should be at the bottom of the DBGrid are strangely not visible. I can use the vertical scroll/elevator bar and/or
TNavigator "End" button, and bring the table pointer to the very bottom of the grid, however, the last record shown in the grid is NOT the last record in the table IF the index is working properly. The more records I add, the more records disappear from the bottom of the grid. If I remove the .NDX files, then all of the records appear in the grid!
E.g, if I have 4 records, and the "last" fields are displayed in the grid "B", "C", "D", "E" at the outset, then as I add "F" to a new record, post it, then add "G" to a new record, then post it, "F" and "G" are missing from the grid! If I add a new record "A", then "E" disappears from the grid. It's as if the index thinks that there are still only 4 records to keep sorted, rather than reindexing itself based upon the new "F", "G" and "A" entries. It's as if the TDBGrid refuses to add more rows!
I therefore suspect that the index file(s) are not getting updated as I add records to the table.
If I delete the .NDX files, and then recreate them, and reattach them, then the grid displays all of the records just fine....until I start adding more records.
What might I be doing wrong?