Delphi Clientdataset处理关联出来的视图的问题

来源:互联网 发布:中兴通软件序列号查询 编辑:程序博客网 时间:2024/06/06 01:54

在Delphi中常常用到ClientDataset来操作视图或者存储过程中关联出来的字段,但是在操作的时候会提示这些字段不能被修改,找了个函数 :

procedure   TLyffMainFrm.SetDstAllFieldCanEdit(dstNm:   TClientDataSet;   AddFields:   string='');
  var   tmpDst:   TClientDataSet;  
          I:   Integer;  
  begin  
      tmpDst   :=   TClientDataSet.Create(nil);  
      Try
          dstNm.DisableControls;
          tmpDst.Data   :=   dstNm.Data;  
          dstNm.Close;  
          dstNm.FieldDefs.Clear;  
          for   I   :=   0   to   tmpDst.FieldDefs.Count   -   1   do  
          begin  
              with   dstNm.FieldDefs.AddFieldDef   do  
              begin  
                  DataType   :=   tmpDst.FieldDefs[I].DataType;  
                  Size   :=   tmpDst.FieldDefs[I].Size;  
                  Name   :=   tmpDst.FieldDefs[I].Name;  
              end;  
          end;  
  //         CreateAttachColumns(dstNm,AddFields);  
          dstNm.CreateDataSet;  
          with   tmpDst   do  
          begin  
              First;  
              while   not   Eof   do  
              begin  
                  dstNm.Append;  
                  for   I   :=   0   to   Fields.Count   -   1   do  
                      dstNm.Fields[I].Value   :=   Fields[I].Value;  
                  Next;  
              end;  
          end;  
          if   dstNm.State   in   [dsInsert,dsEdit]   then   dstNm.Post;  
          dstNm.MergeChangeLog;  
      Finally  
          dstNm.EnableControls;
          tmpDst.Free;
      End;  
  end;

 

用的时候  SetDstAllFieldCanEdit(ClientDataSet1);就可以了。

原创粉丝点击