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.
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).
Text values in formulas are limited to 255 characters. To create text values longer than 255 characters in a formula, use the CONCATENATE function or the concatenation operator (&).
Refer to Multiple lines of text, A Multiple lines of text column can store up to 63,999 characters by default. There's no settings you need to change to allow more than 255 characters.
The limit occurs due to an optimization technique where smaller strings are stored with the first byte holding the length of the string. Since a byte can only hold 256 different values, the maximum string length would be 255 since the first byte was reserved for storing the length.
The Text field is one of the most generic and common data entry fields used to capture text type data—letters, numbers, and symbols. Text fields hold up to 255 characters in a single line.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With