博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
TDataset.CopyFields
阅读量:4697 次
发布时间:2019-06-09

本文共 1901 字,大约阅读时间需要 6 分钟。

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 copiedvar  FieldCtr: Integer;  DestField, SourceField: TField;begin  Result := 0;  for FieldCtr := 0 to Source.FieldCount - 1 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 > 0 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;

 

 

转载于:https://www.cnblogs.com/cb168/p/4269551.html

你可能感兴趣的文章
Binary Agents
查看>>
入门Webpack,看这篇就够了
查看>>
如何在数据库中使用索引
查看>>
ring0
查看>>
windows虚拟机下 安装docker 踩过的坑
查看>>
使用 CXF 做 webservice 简单例子
查看>>
socket.io 消息发送
查看>>
C# 两个datatable中的数据快速比较返回交集或差集
查看>>
关于oracle样例数据库emp、dept、salgrade的mysql脚本复杂查询分析
查看>>
一些有趣的代码
查看>>
Major Performance Impacts
查看>>
读《图解HTTP》有感-(返回结果的HTTP状态码)
查看>>
操作数栈
查看>>
转:文本分类问题
查看>>
tensorflow_python中文手册
查看>>
Vs2012在Linux应用程序开发(3):加入新平台hi3516
查看>>
adb shell am 的用法
查看>>
实现自动点击
查看>>
MVP开发模式的理解
查看>>
Unity多开的方法
查看>>