I'm currently working with a three-tiered hierarchy of Delphi TFrame objects:
TItemsFrame- A base TFrame defining a scrolling area with items.TDrawItemsFrame- A TFrame that overridesTItemsFrameto define how the items are drawn.TFullPage- Another TFrame that extendsTDrawItemsFrame, adding header and footer sections.
The twist comes when I have two different projects that each require a unique way to draw the items, without modifying any descendants of TDrawItemsFrame.
I imagine the solution would look something like this:
- Main project:
type TItemsFrame = Class(TFrame) - Main project:
type TDrawItemsFrame = Class(TItemsFrame) - Main project:
type TFullPage = Class({$I AncestorClass.inc}) - Main project:
type TOtherFullPage = Class({$I AncestorClass.inc})and so on
Then for the individual projects:
- Project A: Define type
TCustom_A_DrawItemsFrame = Class(TDrawItemsFrame)andset AncestorClass.inc to TCustom_A_DrawItemsFrame. - Project B: Define
type TCustom_B_DrawItemsFrame = Class(TDrawItemsFrame)andset AncestorClass.inc to TCustom_B_DrawItemsFrame.
My question is, does this approach align with good Delphi practices, or is there a better Strategy Pattern I should consider to solve this problem? Any insights would be greatly appreciated!
you can do it like Some VCL Components : on the TItemsFrame class expose an event OnDrawItem with all the parameter that can be modified for every item.
Example :
for example the first program :
for example the second program :