In an existing app, a TClientDataSet "Band.CDS" has 3 fields defined using FieldDefs: "Name", "Genre" and "URL". Now want to add a 4th field.
At launch, FormCreate does this:
appPath := ExtractFilePath(Application.ExeName);
BandCDS.FileName := appPath + 'bands.xml'; // an existing file
BandCDS.Active := TRUE;
BandCDS.LoadFromFile(BandCDS.FileName); // load from a file
A TDataSource points to BandCDS, and a TDBGrid points to that TDataSource.
Everything works fine. But I now want to add a 4th field to the TClientDataSet and have it shown to the user (along with the other fields) in the TDBGrid.
What does NOT work: simply adding a fourth item to the FieldDefs for BandCDS.
ADDED INFORMATION ---
At launch, The CDS is loaded from an XML file:
appPath := ExtractFilePath(Application.ExeName);
BandCDS.FileName := appPath + 'bands.xml';
At the end of the session, the CDS is saved back out to the same file:
BandCDS.SaveToFile(BandCDS.FileName, dfXML);
After the file is loaded, I tried changing a field name and adding a new field:
BandCDS.FieldDefs[1].Name := 'NewName';
BandCDS.FieldDefs.Add('A',ftFixedChar,1);
- After that when I examine the FieldDefs, the name HAS been changed, and the new field HAS been added
- However, the DBGrid display is unchanged.
- If I save the file (as mentioned above), exit, and re-launch, we're back to the original names and fields.
- Clearly, the field revisions didn't affect what was output by the SaveToFile.
Thank you! Kevin