I've been haunted by the possibility of single sourcing a Delphi component together with a WinForm component.

Initially, the component was written as a component using Delphi 7. After I completed the development of the component, I started with Delphi 8, to build a completely similar component, in terms of behaviour and functionality.

Once I've a skeleton component created with Delphi 8, I merged together the two components into a single file by using conditional defines. In the .NET version of the Delphi compiler, Delphi defines CLR, MANAGEDCODE and CIL. In the Win32 version of the Delphi compiler, Delphi defines CPU386 and MSWINDOWS.

So, when I merged together the sources for the component, I used the $IF compiler directive, such as

{$IF DEFINED(CLR)}
...block of code...
{$ELSEIF DEFINED(MSWINDOWS)}
...block of code
{$IFEND}

At the same time, I've also used

{$IF NOT DEFINED(CLR)}
 // the following block of code applies to Kylix and Win32
...block of code...
{$ELSE}
// the following block of code applies only to .NET
...block of code...
{$IFEND}

In my component, I had to check whether the component is placed on a form, so that I can manipulate the component's parent's properties.

I used code such as so,

if Assigned(Parent) then // for Win32 and Kylix
   ... block of code...

For CLR, I attempted the following,

AForm := FindForm;
if Assigned(AForm) then // for CLR only
... block of code...

unfortunately, that didn't work. I'm still attempting to find out what's the problem, since Microsoft had documented that FindForm should be able to return the form on which a control is placed.

To be continued...