A tip for using Firemonkey and VCL on different Embarcadero C++ projects

I use Embarcadero C++ for a lot of work. Sometimes Firemonkey is the right framework to use and sometimes VCL is. I have a lot of C++ files that contain classes that are equally useful for both frameworks.

 Instead of having

 #include <fmx.h>

 or

 #include <vcl.h>

at the tops of the files, for all *.cpp files that can be applied equally in either framework, I use the following line:

#include “EmbarcaderoComponentLibrary.h”

The file EmbarcaderoComponentLibrary.h resides in every project I create and is edited once at the start of the project design. It contains the following lines (along with a load of comment statement which I don’t reproduce):

//*****************************************************************

//Set these for each project requirements

#define ROGER_USE_VCL 1

#define ROGER_USE_FMX 0

//******************************************************************/

#ifndef EMBARCADEROCOMPONENTLIBRARY_H

#define EMBARCADEROCOMPONENTLIBRARY_H

#if ROGER_USE_VCL

#include <vcl.h>

 #endif

 #if ROGER_USE_FMX

 #include <fmx.h>

 #endif

 #endif

 //*****************************************************************

 

Advertisements

The First Rule of Software Development

There are many rules that could claim to be the “first rule”…..

 How about:

 “Never have the same data maintained in two different places.”

 If you don’t follow this rule you immediately have a new task of ensuring that the two different places contain the same data and also the headache of what happens when they do contain different data.

 It sounds obvious, but you’d be amazed how many times this rule is violated.