How to make a single component support both VCL and FMX?

  

I have a TComponent which controls some of the UI. This component is designed to support both VCL and Firemonkey by using conditionals. Such conditionals instruct my component whether to accept a VCL control or an FMX control. It’s currently expected that this conditional is defined on the application level to instruct the component in run-time whether it’s to manage a VCL or FMX control.

I’d like to publish my component into the IDE with support for both VCL and FMX, sharing the same unit with conditionals. However, depending on whether VCL or FMX is currently in use, the property names/types differ.

For example…

type
TMyComponent = class(TComponent)
published
{$IFDEF USE_FMX}
property TabControl: TTabControl read FTabControl write SetTabControl;
{$ENDIF}
{$IFDEF USE_VCL}
property PageControl: TPageControl read FPageControl write SetPageControl;
{$ENDIF}
end;

My goal is to be able to drop this non-visual component onto either a VCL or FMX form, and automatically show the appropriate framework-specific properties in the object inspector.

How do I go about registering this component which shares both VCL and FMX code via conditionals?

Comments are closed.