The problem is that DPR will not respect any $ ifdef in the use list and will actually delete them (as you already found) when it rewrites the use list in response to certain IDEs.
One option is to never use these IDE operations, such as Add / Remove Device, etc., and only ever manage the DPR usage list manually.
Alternatively, with little attention, you can use module aliases to achieve what you want.
Consider two devices in which you want to use either on the other or depending on the configuration of the assembly (debugging or release):
- DebugUnit.pas
- ReleaseUnit.pas
In your project options, add a module alias for:
DEBUG Configuration :
UnitToUse=DebugUnit
RELEASE :
UnitToUse=ReleaseUnit
In DPR, add an entry to the use list:
uses UnitToUse,
This entry in DPR cannot identify the file name using the "in" syntax, and should instead rely on the actual units that should be in the project search path.
Anywhere where DebugUnit or ReleaseUnit is commonly used, use UnitToUse instead. Obviously, the name of the alias is completely up to you.
If two blocks have the same “contracts” interface, your assemblies will switch between the two blocks simply by changing the target configuration.
If they have different interface contracts, you can still use the $ ifdef directives in the application code to work with the contents of the unit that UnitToUse refers to, for example,
uses UnitToUse; procedure DoSomethingInvolvingAliasedUnit; begin {$ifdef DEBUG} // code which relies on the debug unit {$else} // code which relies on the release unit {$endif} end;