Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>I'm now developing a few "sister" components which will share a great deal of the existing component's non-visual functionality and properties. It makes sense, then, to move a lot of that to a parent/superclass which both the new and the old components can then inherit from.</p> <p>What is the best way to "refactor" TFrame inheritance in this way?</p> </blockquote> <p>The crux of your text above perhaps is "component's <strong>non-visual</strong> functionality". So, in this case, IMHO it's best to separate the visual and non-visual layers. </p> <p>So, perhaps it's better to use a decorator:</p> <pre><code>TMySharedEngine = class(Whatever) property LinkedFrame: TFrame; property P1; property P2; ... procedure Proc1; procedure Proc2; ... //etc. end; </code></pre> <p>and in your 'sister' frames to use instances of it:</p> <pre><code>var TMyFrame1 = class(TFrame) ... FDecorator: TMySharedEngine; ... public property MySharedPart: TMySharedEngine read FDecorator; constructor Create(AOwner: TComponent); override; ... end; constructor TMyFrame1.(AOwner: TComponent); override; begin inherited; FDecorator:=TMySharedEngine.Create; //ok, ok do not forget to Free it .Destroy FDecorator.LinkedFrame:=Self; ... end; </code></pre> <p>OTOH, if you want to use your approach you can use Visual Form Inheritance (as Darian suggested) or (more flexible) you can do it by hand: Create, using the IDE the following frames: TBaseFrame, TChildFrame1, TChildFrame2 ... etc. Now go on TChildFrame1's unit and change by hand it's class definition from TChildFrame1 = class(TFrame) to TChildFrame1 = class(TBaseFrame). Compile. It should work. It's recommended though that when you'll do this trick TBaseFrame to be empty in order to avoid possible small quirks (feature collisions etc.)</p> <p>HTH.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload