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;
 

TDataset.CopyFields的更多相关文章

  1. delphi之TDataset

    最近遇到了很多问题,现在做一下总结. 字符串处理: 字符串相加 var S1, S2: String; begin S1 := Concat('A', 'B'); // 连接两个字符串,S1变量等于A ...

  2. Delphi7数据库编程之TDataSet(转)

    TDataSet类由TBDEDataSet(BDE组件).TCustomADODataSet(ADO组件).TIBCustomDataSet(InterBase组件).TCustomSQLDataSe ...

  3. Delphi定位TDataSet数据集最后一条记录

    dst_temp.last ;//最后一条dst_temp.first ;//第一条dst_temp.next ;//下一条dst_temp.prior;//上一条

  4. 中间件序列TDATASET为BUFFER演示代码

    procedure SendStream(const AStream: TStream);var Buffer: array[0..4095] of Byte; // 每包最大4K StartPos, ...

  5. FireDACQuery FDQuery New

    FDQuery FDQuery1->ChangeCount;也有UpdatesPending属性 FDQuery1->ApplyUpdates() ExecSQL('select * fr ...

  6. JSON和数据集互相转换单元

    如题......只是一个单元, 为了测试JSON单元性能的... 具体测试结果参考: http://www.cnblogs.com/hs-kill/p/3668052.html 代码中用到的Seven ...

  7. DELPHI XE5 与SQLITE

    最近一次使用DELPHI做项目是使用DELPHI2009,为了访问本地数据库方便,使用ACCESS数据库,不需要安装驱动,(WINDOWS自带),但是ACCESS数据库的性能确实很糟糕,通过ADO连接 ...

  8. Datasnap Image

    delphi用,不能与java.c#互相识别. procedure TServerMethods.UpdateDoc(ItemID : integer; doc : TStream); delphi用 ...

  9. 多层数据库应用基于Delphi DataSnap方法调用的实现(一)返回数据集

    从Delphi 2009开始,DataSnap技术发生了很大的变化,并在Delphi 2010和Delphi XE的后续版本中得到了持续的改进.Delphi 2009之前的DataSnap,虽然也实现 ...

随机推荐

  1. 2-10~2-11 配置iptables防火墙增强服务 selinux简单讲解

    学习一个服务的过程: 1.此服务器的概述:名字,功能,特点,端口号 2.安装 3.配置文件的位置 4.服务启动关闭脚本,查看端口 5.此服务的使用方法 6.修改配置文件,实战举例 7.排错(从下到上, ...

  2. HDU-4511-ac自动机+dp

    小明系列故事——女友的考验 Time Limit: 500/200 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total ...

  3. MyBatis案例&增删改查

    一.MyBatis入门案例: ①:引入jar包 ②:创建实体类 Dept,并进行封装 ③ 在Src下创建大配置mybatis-config.xml <?xml version="1.0 ...

  4. java通过文件头来判断文件类型

    import java.io.FileInputStream; import java.io.IOException; import java.util.HashMap; import java.ut ...

  5. MarkdownPad2 下一些设置

    MarkdownPad2注册码: 邮箱: Soar360@live.com 授权秘钥: GBPduHjWfJU1mZqcPM3BikjYKF6xKhlKIys3i1MU2eJHqWGImDHzWdD6 ...

  6. python学习笔记(一)---python下载以及环境的安装

    转载网址:https://www.runoob.com/python/python-install.html 1.下载python安装包: 安装包下载网址(如下图所在的网址):https://www. ...

  7. oracle修改约束列

    Oracle 增加修改删除字段 添加字段的语法:alter table tablename add (column datatype [default value][null/not null],-. ...

  8. PHP:第五章——字符串与数组及其他函数

    <?php header("Content-Type:text/html;charset=utf-8"); //1.str_split——将字符串转换为数组. /*$str= ...

  9. mmap实现大文件快速拷贝

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

  10. phpstudy2017版本的nginx 支持laravel 5.X配置

    之前做开发和学习一直用phpstudy的mysql服务,确实很方便,开箱即用.QQ群交流:697028234 现在分享一下最新版本的phpstudy2017 laravel环境配置. 最新版的phps ...