Thanks, Cosmin. I appreciate you taking the time to respond. I think that I am
pretty much where you were once upon a time ... I have gotten similar errors,
trying to do similar things, and otherwise been unable to add a field. I've
tried searching the web but I've been unsuccessful. I may just create a CDS
with a lot of blank fields and let users add a fieldName and data to a field as
they need it (all the fields will be the same type and size)--sort of like
using an array instead of a dynamic array, even when you are unsure how many
fields a user will need. I thought there might be a better way to allow users
to add fields as they needed them. For what it's worth, though, here is some
simple code I've used for experimenting in case there are things I'm obviously
doing 'incorrectly' (CDS=TClientDataSet. It's linked to a DBGrid via a
TDataSource component.): //Create a simple dataset
cds.FieldDefs.Add('Field1',ftString,5,True);
cds.FieldDefs.Add('Field2',ftString,5,True); cds.CreateDataSet; cds.Open;
//Save the dataset cds.SaveToFile('test.cds'); cds.Close;{Part of the problem
probably stems from the fact that SaveToFile saves not only data but also
metadata} //Make a dataset with an additional field cds.FieldDefs.Clear;
cds.FieldDefs.Add('Field1',ftString,5,True);
cds.FieldDefs.Add('Field2',ftString,5,True);
cds.FieldDefs.Add('Field3',ftString,5,True); cds.FieldDefs.Update;
cds.CreateDataSet; cds.Open;{Why does new field does not show up in grid at
this point ...?} //Add the previously saved info cds.LoadFromFile('test.cds');
cds.Open;{Presumably the dataset ignores whatever fields may have been created
above and creates only the fields discussed in test.cds} Thanks again -- Al>
Date: Sat, 7 Jul 2007 12:28:03 +0300> From: [EMAIL PROTECTED]> To:
delphi-db@elists.org> > I don't think you can, I think you need to close the
data set, delete> all data, add the extra fields and then re-create the
dataset. But you> can always store the contents of the primary dataset into a
secondary> dataset, re-create the primary dataset to comply with specifications
and> then re-populate it with data from the secondary dataset. This is how>
I've done it before and I clearly remember receiving an error if trying> to add
a field to a already 'created' dataset. Unfortunately I can't> find the code
because, well, it has been changed loooong time ago, it> doesn't exist
anymore.> > Google for 'runtime TClientDataSet' and you'll find some code. Try>
running it on a 'live' dataset. If it fails you know you have to go my> way
(ie: with a secondary dataset).> > --> Cosmin Prund> > > -----Original
Message-----> > > > Hi folks --> > > > Can anyone show me how to add fields at
runtime to an open, already> > existing> > client data set being stored via the
SaveToFile method? I'd like a> user> > to> > be able to see a DBGrid and, with
the click of a menu item, add a new> > field--without losing anything already
in the DB.> > > > Thanks, as always -- Al
_________________________________________________________________
PC Magazine’s 2007 editors’ choice for best web mail—award-winning Windows Live
Hotmail.
http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HMWL_mini_pcmag_0707
_______________________________________________
Delphi-DB mailing list
Delphi-DB@elists.org
http://www.elists.org/mailman/listinfo/delphi-db