Author: Davide Rubbiani
For today’s #DelphiWeek post, I thought I would highlight how you can use existing ClientDataSet (.cds) data in FDMemTable. With this approach, you can also save existing .cds data as JSON, for example. In this tutorial, I am going to create a new application, but you could also use this approach with an existing application.
- Create a new Multi-Device Application (FireMonkey) or VCL Forms Application
- Place a TClientDataSet onto your form
- Place a TFDMemTable onto your form
- Right-click on the TClientDataSet component, and select ‘Load from MyBase table…’
- Browse to your data. In this example, I am using the country.cds file located in C:UsersPublicDocumentsEmbarcaderoStudio15.0SamplesData
- Right-click on FDMemTable and select ‘Assign DataSet’. Select ClientDataSet1 and click OK.
- Next, bind the data to a UI control, such as TGrid using the LiveBindings Designer. This step is optional.
- Select ‘Save to File’ on FDMemTable.
- You can save the data as an XML file, Binary file or JSON file. In this case, I saved it as a JSON file.
- Now you can use this data and load it directly to an FDMemTable component without assigning it to a TClientDataSet component.
Here is a small section of the .JSON data file:
1 |
{"FDBS":{"Version":14,"Manager":{"UpdatesRegistry":true,"TableList":[{"class":"Table","Name":"FDMemTable1","SourceName":"Table","TabID":0,"EnforceConstraints":false,"MinimumCapacity":50,"CheckNotNull":false,"CheckReadOnly":false,"ColumnList":[{"class":"Column","Name":"Name","SourceName":"Name","SourceID":1,"DataType":"AnsiString","Size":24,"Searchable":true,"AllowNull":true,"Unnamed":true,"Base":true,"OAllowNull":true,"OInUpdate":true,"OInWhere":true,"OriginColName":"Name","SourceSize":24},{"class":"Column","Name":"Capital","SourceName":"Capital","SourceID":2,"DataType":"AnsiString","Size":24,"Searchable":true,"AllowNull":true,"Unnamed":true,"Base":true,"OAllowNull":true,"OInUpdate":true,"OInWhere":true,"OriginColName":"Capital","SourceSize":24},{"class":"Column","Name":"Continent","SourceName":"Continent","SourceID":3,"DataType":"AnsiString","Size":24,"Searchable":true,"AllowNull":true,"Unnamed":true,"Base":true,"OAllowNull":true,"OInUpdate":true,"OInWhere":true,"OriginColName":"Continent","SourceSize":24},{"class":"Column","Name":"Area","SourceName":"Area","SourceID":4,"DataType":"Double","Searchable":true,"AllowNull":true,"Unnamed":true,"Base":true,"OAllowNull":true,"OInUpdate":true,"OInWhere":true,"OriginColName":"Area"},{"class":"Column","Name":"Population","SourceName":"Population","SourceID":5,"DataType":"Double","Searchable":true,"AllowNull":true,"Unnamed":true,"Base":true,"OAllowNull":true,"OInUpdate":true,"OInWhere":true,"OriginColName":"Population"}],"ConstraintList":[],"ViewList":[],"RowList":[{"RowID":0,"RowState":"Unchanged","Original":{"Name":"Argentina","Capital":"Buenos Aires","Continent":"South America","Area":2777815,"Population":32300003}},{"RowID":1,"RowState":"Unchanged","Original":{"Name":"Bolivia","Capital":"La Paz","Continent":"South America","Area":1098575,"Population":7300000}},{"RowID":2,"RowState":"Unchanged","Original":{"Name":"Brazil","Capital":"Brasilia","Continent":"South America","Area":8511196,"Population":150400000}}, |
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition