zoukankan      html  css  js  c++  java
  • (原)Lazarus 在 DataSet 转 MemDataSet

    Pascal下 DataSet中的内容是非离线的,就是说需要与数据库保持联机,这样很不好,会弄出很多连接出来,不喜欢。
    MemDataSet,是可以保存离线内容的,于是就有了这个方法。

    function TformMain.DataSet2MDataSet(dataSet:TDataSet):TMemDataSet;
    var
      i:Integer;
      strColumn,strType,strSize,strValue:string;
      mDataset:TMemDataSet;
    begin
      //初始化
      mDataSet:= TMemDataset.Create(nil);
      //字段
      with dataSet do
      for i := 0 to FieldCount-1 do
      begin
         strColumn:= dataSet.Fields[i].FieldName;
         strType:= GetEnumName(TypeInfo(TFieldType),integer(dataSet.Fields[i].DataType)) ;
         strSize:= IntToStr(dataSet.Fields[i].DataSize);
         if strColumn ='SUMNUMBER'then
         Application.MessageBox(Pchar(strType),'',0);
         if (strType ='ftString') or (strType ='ftBCD')then
            mDataSet.FieldDefs.Add(strColumn, TFieldType(GetEnumValue(TypeInfo(TFieldType), strType)),StrToInt(strSize))
         else
            mDataSet.FieldDefs.Add(strColumn, TFieldType(GetEnumValue(TypeInfo(TFieldType), strType)));
      end;
      mDataSet.CreateTable;
      mDataSet.Open;

      //数据
      dataSet.First;
      with dataSet do
        while not dataSet.eof do
         begin
           mDataSet.Append;
           for i := 0 to FieldCount-1 do
            begin
                strValue:= dataSet.Fields[i].AsString;
                mDataSet.Fields[i].AsString:=strValue;
           end;
           dataSet.Next;
         end;
      Result:=mDataSet;
    end;

  • 相关阅读:
    flask基础之jijia2模板使用基础(二)
    python之微信公众号开发(基本配置和校验)
    flask插件系列之SQLAlchemy基础使用
    python基础之常用的高阶函数
    服务器部署之nginx的配置
    python之gunicorn的配置
    python内置模块之unittest测试(五)
    python之celery使用详解一
    git服务器的简单搭建
    python模块分析之logging日志(四)
  • 原文地址:https://www.cnblogs.com/spymaster/p/2126370.html
Copyright © 2011-2022 走看看