How to name files to differentiated VCL and FireMonkey code

  

I have a VCL component that runs on Delphi 7 to 10.3. I am now porting it to FMX.

To avoid maintaining two codebases, I will use conditional defines in my source to separate any custom FMX and VCL code. When I compile the component for distribution a script will output either the VCL or FMX source files.

My problem is how to make the VCL DCUs and FMX DCUs co-exist on the same system (for users who have both the VCL and FMX versions of my component) as both folders will need to be on the Delphi path.

In other words, my VCL units are named: myunit1.pas, myunit2.pas, etc.

And the FMX versions: fmx.myunit1.pas, fmx.myunit2.pas, etc

(Ideally I would name the VCL ones vcl.myunit1.pas, vcl.myunit2.pas, etc. That way the VCL version of the component would only see the vcl.-.pas files and the FireMonkey only the fmx.-.pas files. Unfortunately I cannot do this because then it won’t work on older Delphi versions).

Now when I compile a FireMonkey app it tries to use the non-fmx prefixed source files, in preference to the fmx._.pas ones. I need to “hide” the vcl source folder to get it to compile (re-ordering the Delphi paths does not help).

If there another way to make FireMonkey avoid using the vcl files?

(I fear I will need to write a script to give all the files a new name, e.g. FMXmyunit1.pas and update all of the references in all of the files).

Comments are closed.