title: Correct way to duplicate Delphi object
body: <p>What are pros and cons of duplication an object instance with constructor or instance function?</p>
  
  <p>Example A:</p>
  
  <pre><code>type
    TMyObject = class
    strict private
      FField: integer; 
    public
      constructor Create(srcObj: TMyObject); overload; 
      //alternatively:
      //constructor CreateFrom(srcObj: TMyObject);
      property Field: integer read FField;
    end;
  
  constructor TMyObject.Create(srcObj: TMyObject);
  begin
    inherited Create;
    FField := srcObj.Field;
  end;
  </code></pre>
  
  <p>Example B:</p>
  
  <pre><code>type
    TMyObject = class
    strict private
      FField: integer; 
    public
      function Clone: TMyObject;
      property Field: integer read FField;
    end;
  
  function TMyObject.Clone: TMyObject;
  begin
    Result := TMyObject.Create;
    Result.FField := FField;
  end;
  </code></pre>
  
  <p>One major difference immediately springs to mind - in the latter case the Create constructor would have to be virtual so that a class hierarchy supporting Clone could be built basing on the TMyObject. </p>
  
  <p>Assume that this is not a problem - that TMyObject and everything based on it is entirely under my control. What is your preferred way of doing copy constructor in Delphi? Which version do you find more readable? When would you use former or latter approach? Discuss. :)</p>
  
  <p>EDIT:
  My main concern with the first example is that the usage is very heavy compared to the second approach, i.e.</p>
  
  <pre><code>newObj := TMyObject.Create(oldObj)
  </code></pre>
  
  <p>vs. </p>
  
  <pre><code>newObj := oldObj.Clone;
  </code></pre>
  
  <p>EDIT2 or "Why I want single-line operation"</p>
  
  <p>I agree that Assign is a reasonable approach in most cases. It's even reasonable to implement 'copy constructor' internally by simply using assign.</p>
  
  <p>I'm usually creating such copies when multithreading and passing objects through the message queue. If object creation is fast, I usually pass a copy of the original object because that really simplifies the issues of object ownership.</p>
  
  <p>IOW, I prefer to write</p>
  
  <pre><code>Send(TMyObject.Create(obj));
  </code></pre>
  
  <p>or</p>
  
  <pre><code>Send(obj.Clone);
  </code></pre>
  
  <p>to</p>
  
  <pre><code>newObj := TMyObject.Create;
  newObj.Assign(obj);
  Send(newObj);
  </code></pre>