title: Is there some better way to copy all DataSet Fields and their properties to another DataSet?
body: <p>I'm cloning a TClientDataSet and I want to copy all the fields to the clone (which is a new DataSet), I know I can loop through the Fields and copy the info, or make 2 instances of my class and just clone the cursor, but is there some better way? Something like create a new DataSet and assign the fields info?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>The following class helper method works for me:</p>
  
  <pre><code>procedure TDataSetHelper.CopyFieldDefs(Source: TDataSet);
  var
    Field, NewField: TField;
    FieldDef: TFieldDef;
  begin
    for Field in Source.Fields do
    begin
      FieldDef := FieldDefs.AddFieldDef;
      FieldDef.DataType := Field.DataType;
      FieldDef.Size := Field.Size;
      FieldDef.Name := Field.FieldName;
  
      NewField := FieldDef.CreateField(Self);
      NewField.Visible := Field.Visible;
      NewField.DisplayLabel := Field.DisplayLabel;
      NewField.DisplayWidth := Field.DisplayWidth;
      NewField.EditMask := Field.EditMask;
  
     if IsPublishedProp(Field, 'currency')  then
       SetPropValue(NewField, 'currency', GetPropValue(Field, 'currency'));
  
    end;
  end;
  </code></pre>
  
  <p>Anyone has a better way for doing this?</p>