I have a Delphi 2007 app that interacts with an Access 2000 database. I have made changes to the database structure (addition of fields) and need to make them visible in the Delphi application but that is proving difficult. I made a minimal Delphi application and Access database and the same issue is seen there.
My steps were:
- create an Access database with Field 1 and Field2
- use Settings/Control Panel/Administrative Tools/Data Sources (ODBC 32-bit) to create an alias to the MS database.
- create a Delphi application.
- add a
TDBGridto the form - add a
TDataSourceonto the form - set the
Datasourceproperty of the grid toDataSource1 - add a
TTableto the form - set the
Datasetproperty of theTDataSourcetoTable1 - set the
DataBaseNameproperty ofTable1to the alias name created for the database. - set the
TableNameproperty to the name of the table in your original Access database. - set the
Activeproperty of the Table to TRUE. All the fields originally defined in the database appear in the grid. The problem is when I want to add fields later to this. I can make them appear as columns in the grid by rebuilding the whole thing from scratch, but there must be an easier way!
What is accepted best practice for forcing database structure changes through to the Delphi IDE and resulting application?
** Answer to Ken White's comment **
Thanks Ken. I appreciate the reasons for the Columns property of the DBGrid when you may not want all the fields in your grid - my issue is that when I use MS Access to add some fields to the table and then re-open my Delphi project:
- if I disconnect the
TTableand reconnect it, theFieldDefsproperty shows the added fields. All good. - I then move to the TDBGrid. The displayed columns don't show the additional fields, only the original ones. The
Columnscollection is empty. - when I inspect the
Columnsproperty and try to add all fields I just get the original fields. If I try to add one field` column, the picklist only gives me the original fields to choose from.
I don't understand why the TTable can see the new fields but the TDatasource (which has the TTable specified as it's Dataset property value) cannot.