F_Kind:=FDMemTable2.FieldByName('F_Kind').AsString;
F_Unit:=FDMemTable2.FieldByName('F_Unit').AsString; FDMemTable2.append;
 FDMemTable2.FieldByName('F_Type').Value:=F_Type;
FDMemTable2.FieldByName('F_Unit').Value:=F_Unit;
这是手动的我想根据数据库来,哪些字段设置可以复制行就复制当前行 
   with  FDMemTable1 do
    begin
       while not Eof do
        begin
        if DBGridEh1.FieldColumns[FieldByName('F_field').Value].DisplayText<>'' then
        F_Type:=DBGridEh1.FieldColumns[FieldByName('F_field').Value].DisplayText;
          next;
        FDMemTable2.append;
        FDMemTable2.FieldByName('F_Color').Value:=F_Type;
    end;
    end;
 类似这样

解决方案 »

  1.   

    procedure CopyData(FrData,ToData:TDataSet;NotCopyField:String;Action:String;isPost:Boolean;isCopySysField:Boolean=False);
    var I:integer;
        StrList:TStringList;
    begin
      if not (Todata.State in [dsEdit,dsInsert]) then
      begin
        if Action = 'I' then
          ToData.Insert
        else
        if Action = 'E' then
          ToData.Edit
      end;
      StrList := TStringList.Create;
      if not isCopySysField then
      begin
        StrList.Add('CMCD');
        StrList.Add('CREATEBY');
        StrList.Add('CREATEDT');
        StrList.Add('EDITBY');
        StrList.Add('EDITDT');
        StrList.Add('APPROVALBY');
        StrList.Add('APPROVALDT');
        StrList.Add('STATUSFLAG');
        StrList.Add('REVISION');
      end;
      Crlst(StrList,NotCopyField);
      Try
        for I:= 0 to Todata.FieldCount -1 do
        begin
          if (Todata.Fields[I].DataType <> ftAutoInc) and
             (Todata.Fields[I].FieldKind = fkData) and
             (StrList.IndexOf(ToData.Fields[I].FieldName) = -1) and
             (Frdata.Fields.FindField(Todata.Fields[I].FieldName) <> nil)  then
          begin
            if not Frdata.Fields.FindField(Todata.Fields[I].FieldName).IsNull then        
              Todata.Fields[I].Value := Frdata.Fields.FindField(Todata.Fields[I].FieldName).Value
            else
              Todata.Fields[I].Clear;
          end;
        end;
        if isPost then
          Todata.Post;
      Finally
        StrList.Free;
      end;
    end;这种方式可以不
      

  2.   

    var
      arr:array [0..10] of string;
      I:integer;
    begin
       arr[0]:=FDMemTable1.Fields[0].AsString;
       arr[1]:=FDMemTable1.Fields[1].AsString;
       arr[2]:=FDMemTable1.Fields[2].AsString;
       arr[3]:=FDMemTable1.Fields[3].AsString;
       FDMemTable1.Append;
       FDMemTable1.Fields[0].AsString:=arr[0];
       FDMemTable1.Fields[1].AsString:=arr[1];
       FDMemTable1.Fields[2].AsString:=arr[2];
       FDMemTable1.Fields[3].AsString:=arr[3];end;这个方式也不行
    不过我们也不知道有多少行,所以能不能用i来代替数组里面的序号,i是字段的序号
      

  3.   


    关键只是复制,append而已,不是插入