Description

Often when manipulating datasets with similar structures, you need to copy the records from one dataset to another.  E.g. you may have fetched some records in a query or clientdaset and have located the matching records in another dataset.  You might then want to ensure the record values match without refetching the target dataset.
This looks like it would be easy to implement - i have rewritten it to take care of nested datasets as well as ordinary dataset fields.

Steps to Reproduce:

This is a requested new public method in the base TDataset class.
function TDataSet.CopyFields(Source: TDataSet): Integer;
// copies matching fields in current records- returns number of fields copied
var
FieldCtr: Integer;
DestField, SourceField: TField;
begin
Result := ;
for FieldCtr := to Source.FieldCount - do begin
SourceField := Source.Fields[FieldCtr];
Field := FindField(SourceField.FieldName);
if not Assigned(Field) then Continue;
if Field.ClassType = TDataSetField then begin // nested datasets
while TDataSetField(Field).NestedDataSet.RecordCount > do
TDataSetField(Field).NestedDataSet.Delete;
TDataSetField(SourceField).NestedDataSet.First;
while not TDataSetField(SourceField).NestedDataSet.Eof do begin
TDataSetField(Field).NestedDataSet.Append;
CopyFields(TDataSetField(Field).NestedDataSet, TDataSetField(SourceField).NestedDataSet);
TDataSetField(Field).NestedDataSet.Post;
TDataSetField(SourceField).NestedDataSet.Next;
end;
end else
Field.Value := SourceField.Value;
Inc(Result);
end;
end; This would typically be used as follows: SourceDS.First;
while not SourceDS.EOF do begin
if DestDS.Locate({info required to find matching record}) then begin
DestDS.Edit;
DestDS.CopyFields(SourceDS);
DestDS.Post;
end;
SourceDS.Next;
end;
 

最新文章

  1. Android的setVisibility(View.GONE)无效的问题及原因分析
  2. DS Tree 已知先序、中序 => 建树 => 求后序
  3. [设计模式] javascript 之 装饰者模式
  4. TYVJ P1031 热浪 Label:dijkstra 最短路
  5. HDU 1598 find the most comfortable road 并查集+贪心
  6. 表达式语言之EL表达式
  7. JSP Servlet SQL 三者之间数据传递
  8. C++ map
  9. Kotlin入门第三课:数据类型
  10. js对字符串的一些操作方法
  11. 为什么ssh 执行完命令以后 挂了, hang , stop respond
  12. java基础学习之接口
  13. Android中不能在子线程中更新View视图的原因
  14. c#中//注释和///注释的区别
  15. Java单例模式《一》饿汉式
  16. 在IIS上部署基于django WEB框架的python网站应用
  17. php 显示一个干净的,易被解析的json
  18. Manifold Learning: ISOMAP
  19. CentOS 6.5 源码安装subversion-1.8.8,附加mod_dav_svn模块
  20. Check the difficulty of problems - poj 2151 (概率+DP)

热门文章

  1. 基于Oracle的SQL优化(崔华著)-整理笔记-第5章“Oracle里的统计信息”
  2. 第一个mpvue小程序开发总结
  3. Python 编程核心知识体系-基础|数据类型|控制流(一)
  4. 流程设计器jQuery + svg/vml(Demo4 - 画连线)
  5. Jmeter-Interleave Controller(交替控制器)
  6. 如何在CentOS7上安装MySQL并实现远程访问
  7. 如何搭建Spring MVC 框架---Hello World
  8. Spring获取properties中同一个key对应的多条value的方法
  9. Vim: 有关空格和tab的设置,以及如何全文将空格转成tab
  10. weex入门篇