title: Avoiding code duplication in Delphi
body: <p>I have two components A and B. Component B derives from component A and shares most properties and procedures with it. Now I have a lengthy procedure like this:</p>
  
  <pre><code>procedure DoSomething;
  begin
    Form1.Caption := Component_A.Caption;
    // hundreds of additional lines of code calling component A
  end;
  </code></pre>
  
  <p>Depending on whether component B is active or not, I would like to reuse the above procedure and replace the Component_A part with the name of component B. It should look like this then:</p>
  
  <pre><code>procedure DoSomething;
  var
    C: TheComponentThatIsActive;
  begin
    if Component_A.Active then
      C := Component_A;
    if Component_B.Active then
      C := Component_B;
    Form1.Caption := C.Caption;
  end;
  </code></pre>
  
  <p>How can I do that in Delphi2007?</p>
  
  <p>Thanks!</p>