TCoreDiv

Base container component for all Framework UI components. Provides CSS class support, ElementHandle access, child layout options, and IThemeSubscriber implementation.

Base Component Container IThemeSubscriber

Overview

TCoreDiv is the foundational component that all other Framework UI components inherit from. It extends TWebHTMLDiv with CSS class management, theme subscription, and child layout capabilities.

RULE: ALL UI components must inherit from Core classes (TCoreDiv, TCoreLabel, TCoreButton, etc.) - NEVER use TWebHTMLDiv, TWebLabel, TWebButton directly.

Unit & Inheritance

UNIT Obj.Framework.CoreDiv;

TCoreDiv = CLASS(TWebHTMLDiv, IThemeSubscriber)
   // Implements IThemeSubscriber for automatic theme updates

Published Properties

Property Type Default Description
ChildAlignment TChildAlignment caNone How child controls are aligned: caNone, caCenter, caTop, caBottom, caLeft, caRight.
ChildLayout TChildLayout cdlNone Layout mode for children: cdlNone, cdlVertical, cdlHorizontal, cdlGrid.
ChildOrder Integer 0 CSS flex order value for this component within its parent.
BorderRadius TBorderRadius 0 Corner radius in pixels. Can be uniform or per-corner.
BoxShadow TBoxShadow None Drop shadow configuration with offset, blur, spread, color.
Gap Integer 0 Gap between child elements when using flex/grid layout.

IThemeSubscriber Implementation

TCoreDiv implements IThemeSubscriber, allowing it to receive theme updates automatically when the ThemeManager changes themes.

PROCEDURE ApplyThemeStyles(ThemeManager: TThemeManager);

Called by ThemeManager when theme changes. Override in descendants to apply component-specific styling.

FUNCTION GetSubscriberComponentType: STRING;

Returns the component type identifier used by ThemeManager to look up style definitions. Override to return your component's type (e.g., 'button', 'card', 'header').

Subscribing to ThemeManager

PROCEDURE TMyComponent.Loaded;
VAR
   ThemeManagerInstance: TThemeManager;
BEGIN
   INHERITED;
   
   // Find and subscribe to ThemeManager
   ThemeManagerInstance := FindThemeManager(Self);
   IF Assigned(ThemeManagerInstance) THEN
      BEGIN
         FThemeManager := ThemeManagerInstance;
         ThemeManagerInstance.Subscribe(Self);
      END;
END;

DESTRUCTOR TMyComponent.Destroy;
BEGIN
   // Unsubscribe from ThemeManager
   IF Assigned(FThemeManager) THEN
      FThemeManager.Unsubscribe(Self);
   INHERITED;
END;

Child Layout Options

TChildLayout Enum

Value CSS Behaviour
cdlNone - No layout applied, children use absolute positioning.
cdlVertical flex-direction: column Children stack vertically.
cdlHorizontal flex-direction: row Children arrange horizontally.
cdlGrid display: grid CSS Grid layout mode.

TChildAlignment Enum

Value Behaviour
caNone No alignment applied.
caCenter Center children both horizontally and vertically.
caTop Align children to top.
caBottom Align children to bottom.
caLeft Align children to left.
caRight Align children to right.

Position Locking (Design-Time)

TCoreDiv supports position locking for sub-components at design time, preventing the IDE from repositioning them.

PROCEDURE LockPosition(ALeft, ATop: Integer);

Locks the component to a specific position. Used by TMultiContainer for its sub-regions.

PROCEDURE UnlockPosition;

Unlocks position, allowing normal positioning.

Sub-Component Variants

Two special variants exist for use as sub-components:

TSubCoreDiv

A TCoreDiv variant with NO published properties. Used where you want a child div that doesn't clutter the Object Inspector (e.g., TMultiContainer.FooterContent).

Usage Pattern

// In parent component:
FFooterContent := TSubCoreDiv.Create(FormOwner);
FFooterContent.Parent := Self;
FFooterContent.Name := Name + 'Footer';

// In interface section, expose as published property:
PROPERTY FooterContent: TSubCoreDiv READ FFooterContent WRITE FFooterContent;

CSS Class Application

TCoreDiv automatically adds a CSS class based on its component type. Use TDom.AddClass to add additional classes:

CONSTRUCTOR TMyCard.Create(AOwner: TComponent);
BEGIN
   INHERITED;
   TDom.AddClass(Self, CssClassDashboardCard);
   TDom.AddClass(Self, 'my-custom-class');
END;

See Also