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;

  • 相关阅读:
    P1410 子序列
    P1395 会议 (树形dp)
    P2580 于是他错误的点名开始了
    LC1127. 用户购买平台
    LC 1308. Running Total for Different Genders
    P1340 兽径管理 (最小生成树)
    P1330 封锁阳光大学 (二分图染色)
    CF1296F Berland Beauty (Tree, dfs/bfs, LCA)
    顺丰的Cookie条款
    服务器判断客户端的用户名和密码(token的身份验证)
  • 原文地址:https://www.cnblogs.com/spymaster/p/2126370.html
Copyright © 2011-2022 走看看