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. 一张思维导图教你使用google一下

    导图总览 google搜索技巧.png 双引号 代表完全匹配搜索 也就是说搜索结果返回的页面包含双引号中出现的所有的词,连顺序也必须完全匹配 例如搜索"java 排序"与无引号的j ...

  2. 007PHP文件处理—— 判断文件与操作文件fopen fread fclose is_executable is_readable is_writeable

    <?php /** * 判断文件与操作文件fopen fread fclose * is_executable is_readable is_writeable */ //判断一个文件是不是一个 ...

  3. 2018.11.29 Wireless technology roadmap(1)

    1物联网还是卖开发板阶段. BT NBIoT 窄带物联网(Narrow Band Internet of Things) Sigfox Zigbee Wifi:大数据量传输 LoRA :远距离无线电( ...

  4. Nginx 反向代理 如何在web应用中获取用户ip

    转载:http://blog.csdn.net/bao19901210/article/details/52537279 问题背景: 在实际应用中,我们可能需要获取用户的ip地址,比如做异地登陆的判断 ...

  5. Linux的发行版之间的联系和区别

    转载:https://blog.csdn.net/suixin788/article/details/52555558 联系 Linux的内核源代码和Linux的应用程序都可以自由获得,因此很多公司组 ...

  6. 中南林业科技大学第十一届程序设计大赛- I:背包问题

    链接:https://www.nowcoder.com/acm/contest/124/I来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒空间限制:C/C++ 131072K,其他语言26214 ...

  7. DesignPattern(三)结构型模式(上)

    结构型模式 结构型模式,顾名思义讨论的是类和对象的结构 ,主要用来处理类或对象的组合.它包括两种类型,一是类结构型模式,指的是采用继承机制来组合接口或实现:二是对象结构型模式,指的是通过组合对象的方式 ...

  8. test20181020 B君的第一题

    题意 分析 二次剩余问题. x,y相当于二次方程 \[ x^2-bx+c=0 \mod{p} \] 的两根. 摸意义下的二次方程仍然考虑判别式\(\Delta=b^2-4c\). 它能开根的条件是\( ...

  9. oracle 查版本号

    oracle是强大的数据库,我们怎样看它的版本呢? 工具/原料 oracle 数据库, sqlplus 方法/步骤 首先进入sqlplus,cmd---plsql,登陆我们的用户,如:user/pas ...

  10. anrdroid AVD启动不起来的问题。Waiting for HOME ('android.process.acore') to be launched

    Waiting for HOME ('android.process.acore') to be launched 卡在这里了. 可以到sdk mananager里面先启动起来AVD,然后在eclip ...