procedure CopyRecord(Source, Destination: TDataSet); var Ind:longint; SField, DField: TField; begin for Ind:=0 to Source.FieldCount - 1 do begin SField := Source.Fields[ Ind ]; DField := Destination.FindField( SField.FieldName ); if (DField <> nil) and (DField.FieldKind = fkData) and not DField.ReadOnly then if (SField.DataType = ftString) or (SField.DataType <> DField.DataType) then DField.AsString := SField.AsString else DField.Assign( SField ) end; end;
旧方法:
DEST.Open; ORIGIN.Open; while not ORIGIN.Eof do begin if ORIGINTYPE.AsString = 'T' then with ORIGIN do begin DEST.Append; DEST.FieldByName('TYPE').AsString := ORIGINTYPE.AsString; DEST.FieldByName('FIRSTNAME').AsString := ORIGINFIRSTNAME.AsString; DEST.FieldByName('LASTNAME').AsString := ORIGINLASTNAME.AsString; DEST.FieldByName('CPF').AsString := ORIGINCPF.AsString; DEST.FieldByName('PARTY').AsString := ORIGINPARTY.AsString; DEST.Post; end; ORIGIN.Next; end;
使用该过程的调用示范:
DEST.Open; ORIGIN.Open; while not ORIGIN.Eof do begin if ORIGINTYPE.AsString = 'T' then begin DEST.Append; CopyRecord( ORIGIN, DEST ); DEST.Post; end; ORIGIN.Next; end;