I have a few classes with complex business rules and processes, but I’ve just been INCLUDEing them wherever I needed, resulting in their code being compiled in all the dlls.
After some unexpected behavior caused by this, I decided to create a new dll with all the classes and properly export them.
I found a post by also where he explains the EXPORT attribute, and it works great for classes.
One limitation of EXPORT is that it doesn’t have a conditional parameter (like DLL or LINK) so the class must have its first line declared twice with conditional compilation. After a few iterations, I’ve arrived at a source code format that I think is simple to implement and readable.
This is how the inc file looks like:
COMPILE('|',ExportClasses=1)
ExampleClassType CLASS,MODULE('ExampleClassType'),LINK('ExampleClassType',1),EXPORT,TYPE |
COMPILE('|',ExportClasses=0)
ExampleClassType CLASS,MODULE(''),DLL(1),TYPE |
ExampleMethod PROCEDURE(STRING pText,BOOL pUpper = FALSE),STRING
END
In the dll where the classes are exported, you only need two lines:
ExportClasses EQUATE(1)
INCLUDE('ExampleClassType.inc'),ONCE
And in all the other dlls and exes, the normal line:
INCLUDE('ExampleClassType.inc'),ONCE
There is no need to add flags to the project, as the EQUATE handles the conditional compile. And, of course, there is no need to add anything to the .exp file, because the EXPORT attribute takes care of that.
I decided to use COMPILE('|'...) and a superfluos line continuation symbol | to save two lines in the class declaration, and COMPILE(...,flag=0) instead of OMIT for better readability.
Since the conditional compilation is handling which line to use, there is no need to use flags in the class declarations, so I used 1 and '' as parameters for LINK, DLL and MODULE, and omitted them where appropriate.
Here is a simple test project in github.
Carlos