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. Aizu-2200-floyd+dp

    Mr. Rito Post Office 你是一个为远程邮局邮局工作的程序员.你住的地区由几个岛屿组成.每个岛屿都有一个或多个港口城镇.除此之外,还有其他城镇和村庄.为了从一个岛到另一个岛,你必须使用 ...

  2. nyoj1273 河南省第九届省赛_"宣传墙"、状压DP+矩阵幂加速

    宣传墙 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 ALPHA 小镇风景美丽,道路整齐,干净,到此旅游的游客特别多.CBA 镇长准备在一条道路南 面 4*N 的墙上做 ...

  3. c++ 中的 set

    set (集合) 中的元素是排序好的,而且是不重复的. 例题:hdu 4989 题目大意:求一组数列中任意两个不重复元素和,再求不重复和的和. #include <bits/stdc++.h&g ...

  4. C#属性升级版--自动属性-chapter 3 P34-36

    使用C#属性,能够通过将数据与它的设置和检索方法分离的方式公开类中的一段数据.   例如:   namespace LanguageFeatures { public class Product { ...

  5. [ccf 4] 网络延时

    网络延时 问题描述 给定一个公司的网络,由n台交换机和m台终端电脑组成,交换机与交换机.交换机与电脑之间使用网络连接.交换机按层级设置,编号为1的交换机为根交换机,层级为      1.他的交换机都连 ...

  6. C++轮子队

    团队Github地址:https://github.com/Pryriat/2048.git 团队展示: 队名:C++轮子队 队员组成: 黄家承(队长)              学号:3116005 ...

  7. L172 K-kilogram

    In a historic vote, nations on Friday unanimously approved a groundbreaking overhaul to the internat ...

  8. 代码控制 textarea 控件是否为KindEditor 编辑框

    <script charset="utf-8" src="<%:Url.Content("~/UI/Scripts/KindEditor/kinde ...

  9. JSON.js 源码学习..

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. HDU 3667

    http://acm.hdu.edu.cn/showproblem.php?pid=3667 最小费用最大流 本题流量和费用不是线性关系,fee=a*flow*flow,所以常规套模板spfa无法得到 ...