Hi Brad, The ClientDataset has built in XML capabilities. Simply set the Filename property to the path and name of the XML file and set active to True. All fields and data should be shown in a grid for you.
Mike ----- Original Message ----- From: "Gies,Brad" <[EMAIL PROTECTED]> To: "Delphi-Talk Discussion List" <[email protected]> Sent: Tuesday, October 11, 2005 7:30 AM Subject: RE: Adding a field to a ClientDataSet at runtime > > > I'm trying to do it in the Datamodule.create, so it's before it is > viewed, but the DataSet is already created. > > I should explain more clearly. I'm trying to separate the fields that > are used in the XML that comes in (which I don't have complete control > of) from the fields which I need in the program to have the program work > well. With the XML feed, I have access to the .cds file and the > transformation files needed to transform the data into the dataset > needed to hold it, so I want to use that to load my clientDataSet > fields, and then add the fields my program needs. It will make upgrades > go much more smoothly. > > Right now, I'm trying to UnCreate the DataSet, without losing the > FieldDefs, add the FieldDefs I need, and then use CreateDataSet. Any > idea how to do that???? > > Sincerely, > > Brad Gies > ------------------------------------- > NLM Software > Southfield, MI, USA > ------------------------------------- > > > > > > > -----Original Message----- > > From: [EMAIL PROTECTED] [mailto:delphi-talk- > > [EMAIL PROTECTED] On Behalf Of M Tuttle (KS) > > Sent: Tuesday, October 11, 2005 8:23 AM > > To: Delphi-Talk Discussion List > > Subject: Re: Adding a field to a ClientDataSet at runtime > > > > Hi Brad, > > > > Maybe I spoke too soon. Are you trying to create a new field before > or > > after your dataset is opened? If you are asking how to do it after > you > > have > > the dataset open and your are viewing your data, then I spoke to soon. > If > > you are wanting to add the field just before you open it then you > should > > be > > fine. Place the code I gave you in the OnBeforeOpen of the > ClientDataset. > > > > Mike > > > > ----- Original Message ----- > > From: "Gies,Brad" <[EMAIL PROTECTED]> > > To: "Delphi-Talk Discussion List" <[email protected]> > > Sent: Tuesday, October 11, 2005 7:06 AM > > Subject: RE: Adding a field to a ClientDataSet at runtime > > > > > > > No, there are no queries involved. I'm trying your procedures right > now. > > > Will let you know if they work for me. > > > > > > > > > > > > Sincerely, > > > > > > Brad Gies > > > ------------------------------------- > > > NLM Software > > > Southfield, MI, USA > > > ------------------------------------- > > > > > > > > > > > > > > > > > > > -----Original Message----- > > > > From: [EMAIL PROTECTED] [mailto:delphi-talk- > > > > [EMAIL PROTECTED] On Behalf Of M Tuttle (KS) > > > > Sent: Tuesday, October 11, 2005 12:15 AM > > > > To: Delphi-Talk Discussion List > > > > Subject: Re: Adding a field to a ClientDataSet at runtime > > > > > > > > Hi Brad, > > > > > > > > I asked "Do you also need to add these fields to a query?" > > > > > > > > If the ClientDataset is tied to a Query and not used as an > in-memory > > > > dataset > > > > then you must first add it to the query before adding it to the > > > > ClientDataset. > > > > > > > > I know this works because we build our queries and clientdatasets > on > > > the > > > > fly > > > > as needed in out program. > > > > > > > > Here is three actual procedures that we use to create 3 different > > > query > > > > fields (Integer, Date and String): > > > > > > > > > > > > {----------------------------------------------------------------------- > > > -- > > > > -- > > > > -- > > > > Procedure: AddQueryStringField > > > > Author: Michael Tuttle > > > > Date: 2001 > > > > Purpose: > > > > > > > > ------------------------------------------------------------------------ > > > -- > > > > -- > > > > -} > > > > procedure TdtmAccountRem.AddQueryStringField(Query: TIBQuery; > FldName: > > > > String; > > > > FldKind: TFieldKind; FieldSize: Integer); > > > > var > > > > fldString: TStringField; > > > > begin > > > > fldString := TStringField.Create(Query); > > > > > > > > with fldString do > > > > begin > > > > FieldName := FldName; > > > > FieldKind := FldKind; > > > > DisplayLabel := FieldName; > > > > Size := FieldSize; > > > > DataSet := Query; > > > > Name := Query.Name + FieldName; > > > > ProviderFlags := []; > > > > end; > > > > > > > > with Query.FieldDefs do > > > > begin > > > > Add(fldString.Name, ftString, FieldSize, False); > > > > Update; > > > > end; > > > > end; > > > > > > > > > > > > {----------------------------------------------------------------------- > > > -- > > > > -- > > > > -- > > > > Procedure: AddQueryDateField > > > > Author: Michael Tuttle > > > > Date: 2001 > > > > Purpose: > > > > > > > > ------------------------------------------------------------------------ > > > -- > > > > -- > > > > -} > > > > procedure TdtmAccountRem.AddQueryDateField(Query: TIBQuery; > FldName: > > > > String; > > > > FldKind: TFieldKind); > > > > var > > > > fldDate: TDateField; > > > > begin > > > > fldDate := TDateField.Create(Query); > > > > > > > > with fldDate do > > > > begin > > > > FieldName := FldName; > > > > FieldKind := FldKind; > > > > DisplayLabel := FieldName; > > > > DataSet := Query; > > > > Name := Query.Name + FieldName; > > > > ProviderFlags := []; > > > > end; > > > > > > > > with Query.FieldDefs do > > > > begin > > > > Add(fldDate.Name, ftDate, 0, False); > > > > Update; > > > > end; > > > > end; > > > > > > > > > > > > {----------------------------------------------------------------------- > > > -- > > > > -- > > > > -- > > > > Procedure: AddQueryIntegerField > > > > Author: Michael Tuttle > > > > Date: 2001 > > > > Purpose: > > > > > > > > ------------------------------------------------------------------------ > > > -- > > > > -- > > > > -} > > > > procedure TdtmAccountRem.AddQueryIntegerField(Query: TIBQuery; > > > FldName: > > > > String; > > > > FldKind: TFieldKind); > > > > var > > > > fldIntegerField: TIntegerField; > > > > begin > > > > fldIntegerField := TIntegerField.Create(Query); > > > > > > > > with fldIntegerField do > > > > begin > > > > FieldName := FldName; > > > > FieldKind := FldKind; > > > > DisplayLabel := FieldName; > > > > DataSet := Query; > > > > Name := Query.Name + FieldName; > > > > ProviderFlags := []; > > > > end; > > > > > > > > with Query.FieldDefs do > > > > begin > > > > Add(fldIntegerField.Name, ftInteger, 0, False); > > > > Update; > > > > end; > > > > end; > > > > > > > > Here is an example call: > > > > AddQueryIntegerField(qryAddress, PERSON_ID, fkData); > > > > > > > > Again create the query field first then the clientdataset field. > We > > > do it > > > > all the time. > > > > > > > > Good luck and let me know how this works out for you. > > > > > > > > Mike > > > > > > > > ----- Original Message ----- > > > > From: "Gies,Brad" <[EMAIL PROTECTED]> > > > > To: "Delphi-Talk Discussion List" <[email protected]> > > > > Sent: Monday, October 10, 2005 7:43 PM > > > > Subject: RE: Adding a field to a ClientDataSet at runtime > > > > > > > > > > > > > Mike, > > > > > > > > > > Are you sure about that? Reading the help for update sounds like > it > > > > > looks at the fields and updates the definitions according to the > > > fields, > > > > > not the fields according to the definitions. I'll try it anyway > > > though. > > > > > > > > > > I have tried just creating a new TField Object and adding it to > the > > > > > ClientDataSet using the Fields.Add method, but when trying to > add a > > > > > value to the field it couldn't find it. I'm not sure why. > > > > > > > > > > > > > > > Sincerely, > > > > > > > > > > Brad Gies > > > > > ------------------------------------- > > > > > NLM Software > > > > > Southfield, MI, USA > > > > > ------------------------------------- > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -----Original Message----- > > > > > > From: [EMAIL PROTECTED] [mailto:delphi-talk- > > > > > > [EMAIL PROTECTED] On Behalf Of M Tuttle (KS) > > > > > > Sent: Monday, October 10, 2005 7:58 PM > > > > > > To: Delphi-Talk Discussion List > > > > > > Subject: Re: Adding a field to a ClientDataSet at runtime > > > > > > > > > > > > Something like this. Do you also need to add these field to a > > > query? > > > > > > > > > > > > Procedure SomeProcedure > > > > > > var > > > > > > fldStringField: TStringField; > > > > > > fldIntegerField: TIntegerField; > > > > > > begin > > > > > > > > > > > > with cdsAddress do > > > > > > begin > > > > > > //* Add the persistent field > > > > > > with FieldDefs do > > > > > > begin > > > > > > fldIntegerField := > TIntegerField.Create(cdsAddress); > > > > > > with fldIntegerField do > > > > > > begin > > > > > > FieldName := 'FIELD_NAME'; > > > > > > DisplayLabel := FieldName; > > > > > > DataSet := cdsAddress; > > > > > > Name := cdsAddress.Name + FieldName; > > > > > > > cdsAddress.FieldDefs.Add(fldIntegerField.Name, > > > > > > ftInteger, > > > > > > 0, False); > > > > > > end; > > > > > > > > > > > > fldStringField := TStringField.Create(cdsAddress); > > > > > > with fldStringField do > > > > > > begin > > > > > > FieldName := 'ANOTHER_FIELD_NAME'; > > > > > > DisplayLabel := FieldName; > > > > > > DataSet := cdsAddress; > > > > > > Name := cdsAddress.Name + FieldName; > > > > > > > cdsAddress.FieldDefs.Add(fldStringField.Name, > > > > > ftString, > > > > > > 1, > > > > > > False); > > > > > > end; > > > > > > > > > > > > //* Update the field defs > > > > > > Update; > > > > > > end; > > > > > > end; > > > > > > end: > > > > > > > > > > > > ----- Original Message ----- > > > > > > From: "Gies,Brad" <[EMAIL PROTECTED]> > > > > > > To: "Delphi-Talk Discussion List" <[email protected]> > > > > > > Sent: Monday, October 10, 2005 6:44 PM > > > > > > Subject: Adding a field to a ClientDataSet at runtime > > > > > > > > > > > > > > > > > > > > > > > > > > Does anyone know how to add a new field to a ClientDataSet > after > > > the > > > > > > > DataSet is already created? Is it possible? > > > > > > > > > > > > > > Sincerely, > > > > > > > > > > > > > > Brad Gies > > > > > > > ------------------------------------- > > > > > > > NLM Software > > > > > > > Southfield, MI, USA > > > > > > > ------------------------------------- > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > This e-mail is intended only for the person or entity to > which > > > it is > > > > > > addressed and may > > > > > > > contain confidential and/or privileged material. Any > review, > > > > > > retransmission, > > > > > > > dissemination or other use of, or taking of any action in > > > reliance > > > > > upon, > > > > > > this information > > > > > > > by persons or entities other than the intended recipient is > > > > > prohibited. > > > > > > If you > > > > > > > received this message in error, please contact the sender > > > > > immediately > > > > > > and > > > > > > delete > > > > > > > the material from your computer. > > > > > > > __________________________________________________ > > > > > > > Delphi-Talk mailing list -> [email protected] > > > > > > > http://www.elists.org/mailman/listinfo/delphi-talk > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > __________________________________________________ > > > > > > Delphi-Talk mailing list -> [email protected] > > > > > > http://www.elists.org/mailman/listinfo/delphi-talk > > > > > > > > > > > > > > > This e-mail is intended only for the person or entity to which > it is > > > > addressed and may > > > > > contain confidential and/or privileged material. Any review, > > > > retransmission, > > > > > dissemination or other use of, or taking of any action in > reliance > > > upon, > > > > this information > > > > > by persons or entities other than the intended recipient is > > > prohibited. > > > > If you > > > > > received this message in error, please contact the sender > > > immediately > > > > and > > > > delete > > > > > the material from your computer. > > > > > __________________________________________________ > > > > > Delphi-Talk mailing list -> [email protected] > > > > > http://www.elists.org/mailman/listinfo/delphi-talk > > > > > > > > > > > > > > > > > > > > > > __________________________________________________ > > > > Delphi-Talk mailing list -> [email protected] > > > > http://www.elists.org/mailman/listinfo/delphi-talk > > > > > > > > > This e-mail is intended only for the person or entity to which it is > > addressed and may > > > contain confidential and/or privileged material. Any review, > > retransmission, > > > dissemination or other use of, or taking of any action in reliance > upon, > > this information > > > by persons or entities other than the intended recipient is > prohibited. > > If you > > > received this message in error, please contact the sender > immediately > > and > > delete > > > the material from your computer. > > > __________________________________________________ > > > Delphi-Talk mailing list -> [email protected] > > > http://www.elists.org/mailman/listinfo/delphi-talk > > > > > > > > > > > > __________________________________________________ > > Delphi-Talk mailing list -> [email protected] > > http://www.elists.org/mailman/listinfo/delphi-talk > > > This e-mail is intended only for the person or entity to which it is addressed and may > contain confidential and/or privileged material. Any review, retransmission, > dissemination or other use of, or taking of any action in reliance upon, this information > by persons or entities other than the intended recipient is prohibited. If you > received this message in error, please contact the sender immediately and delete > the material from your computer. > __________________________________________________ > Delphi-Talk mailing list -> [email protected] > http://www.elists.org/mailman/listinfo/delphi-talk > > __________________________________________________ Delphi-Talk mailing list -> [email protected] http://www.elists.org/mailman/listinfo/delphi-talk
