How to overcome 255 character limit on conditional defines?
Asked Answered
C

2

5

Conditional defines in Delphi are limited to 255 characters. That means that if you have more than 255 characters of defines, they are ignored. E.g.

enter image description here

So the set of conditional defines:

Win32API;AlarmServerEngineVersion27;ImNotUsingOlderSimpleThread;EnableJclExceptionTracking;SaveExceptionsToDatabase;ShowExceptionForm;SNAPIN_NEEDS_NODE_DESCRIPTOR;VIRTUAL_TREES_MOUSE_DOWN_FOCUS_LAST;UseSQLServerLocking;SnapInFactoryFormClassIsOptional;Strict;SIFFCIO;Sqm

The last 3 defines are ignored.

What i need is a way to define conditional defines in the project, while not being limited to 255 characters.

i thought maybe moving the conditional defines to the project source file, perhaps included through in include file:

program ConsotoManager;

{$R *.RES}
{$R '..\Resource\Wumpa.res' '..\Resource\Wumpa.rc'}
{$DEFINE Win32API}
...
{$DEFINE Sqm}
{$DEFINE Strict}

uses
  FastMM4,
  Windows,
  SysUtils,

Unfortunately it doesnt' work. The reason it doesn't work is that you cannot substitute defines for conditional defines; defines only last until the end of the file.

So, how do i overcome the 255 character limit on Conditional Defines in Delphi?


The problem, of course, is how to have project level defines, while have shared source code files (shared files are in their own directories, outside of the project folder).

Cirro answered 15/7, 2013 at 17:32 Comment(0)
G
9

You're almost there with the definitions in the project file, but remember that Delphi isn't C — the compiler doesn't read each mentioned unit in sequence each time it compiles anything, as though all the files were pasted together textually, so things defined in the project file won't be visible outside that file.

However, Delphi is like C in that it supports a directive named include that does cause it to re-read the mentioned file on every compilation. Let's use that.

First, put all your definitions into a separate text file. Let's call it Defines.inc.

{$DEFINE Win32API}
...
{$DEFINE Sqm}
{$DEFINE Strict}

Then include that file into all the source files that need any of those definitions.

program ConsotoManager;

{$R *.RES}
{$R '..\Resource\Wumpa.res' '..\Resource\Wumpa.rc'}
{$INCLUDE Defines.inc}

uses
  FastMM4,
  Windows,

Now you can clear the list in your project options and instead add whatever definitions you need to that file. When you change that file, you might need to do a full build (rather than a simple compile) in order for the changes to take effect.

Also, consider whether you really need so many compilation variables. Maybe some of them are always defined, so it doesn't make sense to check them at compilation time. Maybe some of them are redundant.

Growl answered 15/7, 2013 at 18:11 Comment(2)
The problem is shared files. They have 15 years of new features, and backwards compatibility, which are either opted into, or out of, per-project. If i add {$INCLUDE Defines.inc} to the top of VirtualTrees.pas, it won't work because it won't be able to find Defines.inc (since Defines.inc is sitting in my project's source folder. And even if it did work, i would introduce a breaking change to the library, as none of the other projects will have this Defines.inc file.Cirro
i have started to make the define Strict enable the other defines. So you can define Strict, which will automatically enable some of the other defines. i also made the define inuost enable the define ImNotUsingOlderSimpleThread, as a way to save precious characters. What i need a place in the project to put "conditional define" that operate over all compiled units; not just until the end of the unit they're defined in.Cirro
I
0

My Delphi is a little rusty, but I believe you can create a define that represents all those others are defined aswell, so you only have to check for one condition.

{$IF    Defined(Win32API)
    AND Defined(AlarmServerEngineVersion27)
    AND Defined(ImNotUsingOlderSimpleThread)
    AND Defined(EnableJclExceptionTracking)
    AND Defined(SaveExceptionsToDatabase)
    AND Defined(ShowExceptionForm)
    AND Defined(SNAPIN_NEEDS_NODE_DESCRIPTOR)
    AND Defined(VIRTUAL_TREES_MOUSE_DOWN_FOCUS_LAST)
    AND Defined(UseSQLServerLocking)
    AND Defined(SnapInFactoryFormClassIsOptional)
    AND Defined(Strict)
    AND Defined(SIFFCIO)
    AND Defined(Sqm)
}
{$DEFINE I_AM_TOTALLY_READY}
{$IFEND}
Incommensurable answered 15/7, 2013 at 17:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.