分享

Using existing ClientDataSet data in FDMemTable

 quasiceo 2017-07-01

Using existing ClientDataSet data in FDMemTable

Posted by on in Data

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.

  1. Create a new Multi-Device Application (FireMonkey) or VCL Forms Application
  2. Place a TClientDataSet onto your form
  3. Place a TFDMemTable onto your form
  4. Right-click on the TClientDataSet component, and select 'Load from MyBase table...'LoadMybase
  5. Browse to your data. In this example, I am using the country.cds file located in C:\Users\Public\Documents\Embarcadero\Studio\15.0\Samples\Data 
  6. Right-click on FDMemTable and select 'Assign DataSet'. Select ClientDataSet1 and click OK.AssignDataSet
  7. Next, bind the data to a UI control, such as TGrid using the LiveBindings Designer. This step is optional.
    LBDesigner2
  8. Select 'Save to File' on FDMemTable. 
    SaveToFile
  9. You can save the data as an XML file, Binary file or JSON file. In this case, I saved it as a JSON file. 
    SaveAsDialog
  10. Now you can use this data and load it directly to an FDMemTable component without                         assigning it to a TClientDataSet component.

             LoadFromFile

JsonFile

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}},

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多