Use or absence of use of DEBUG conditional definition

I had an idea to use FastMM4 in FullDebugMode when compiling my project with Debug Build configuration.

When I selected the Debug assembly configuration, Delphi automatically sets DEBUG as a conditional definition. So this code should work as expected:

unit uXTrackUpdater; program Test; uses {$IFDEF DEBUG}FastMM4,{$ENDIF} Forms; {$R *.res} begin Application.Initialize; Application.MainFormOnTaskbar := True; Application.Title := 'Test'; Application.CreateForm(TfrmTest, frmMain); Application.Run; 

And it works. However, when I change the assembly configuration to the Release configuration. This code also works! And should not? Because the DEBUG condition should not be defined.

So, can someone explain to me why this code is executed regardless of the assembly configuration and how to configure it correctly (so that FastMM4 will be compiled only when using the debug configuration).

After editing

With FastMM, this was just an example. Before posting my question here, I tested it in another case. Here he is:

 program Project21; {$APPTYPE CONSOLE} uses {$IFDEF DEBUG} SysUtils; {$ENDIF} begin try { TODO -oUser -cConsole Main : Insert code here } except on E:Exception do //should not be found after rebuilding with RELEASE build configuration Writeln(E.Classname, ': ', E.Message); end; end. 

The code above will compile regardless of the build configuration. Why?

After the second edit

I know that others say that my examples work as expected. But they do not work for me. I tested this behavior on Delphi 2010 and it is identical (still not working).

Perhaps this will be useful: I replaced the DEBUG directive with RELEASE to find out what would happen. The result was that RELEASE meant that my sample code would not build in both configurations.

Third edit:

My dproj file:

 <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <ProjectGuid>{E9F0DC1F-23EC-46AA-97F8-68C007E77218}</ProjectGuid> <ProjectVersion>12.0</ProjectVersion> <MainSource>Project21.dpr</MainSource> <Config Condition="'$(Config)'==''">Debug</Config> <DCC_DCCCompiler>DCC32</DCC_DCCCompiler> </PropertyGroup> <PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''"> <Base>true</Base> </PropertyGroup> <PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_1)'!=''"> <Cfg_1>true</Cfg_1> <CfgParent>Base</CfgParent> <Base>true</Base> </PropertyGroup> <PropertyGroup Condition="'$(Config)'=='Debug' or '$(Cfg_2)'!=''"> <Cfg_2>true</Cfg_2> <CfgParent>Base</CfgParent> <Base>true</Base> </PropertyGroup> <PropertyGroup Condition="'$(Base)'!=''"> <DCC_DependencyCheckOutputName>Project21.exe</DCC_DependencyCheckOutputName> <DCC_ImageBase>00400000</DCC_ImageBase> <DCC_UnitAlias>WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;$(DCC_UnitAlias)</DCC_UnitAlias> <DCC_Platform>x86</DCC_Platform> <DCC_E>false</DCC_E> <DCC_N>false</DCC_N> <DCC_S>false</DCC_S> <DCC_F>false</DCC_F> <DCC_K>false</DCC_K> </PropertyGroup> <PropertyGroup Condition="'$(Cfg_1)'!=''"> <DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols> <DCC_Define>RELEASE;$(DCC_Define)</DCC_Define> <DCC_SymbolReferenceInfo>0</DCC_SymbolReferenceInfo> <DCC_DebugInformation>false</DCC_DebugInformation> </PropertyGroup> <PropertyGroup Condition="'$(Cfg_2)'!=''"> <DCC_Define>DEBUG;$(DCC_Define)</DCC_Define> </PropertyGroup> <ItemGroup> <DelphiCompile Include="Project21.dpr"> <MainSource>MainSource</MainSource> </DelphiCompile> <BuildConfiguration Include="Base"> <Key>Base</Key> </BuildConfiguration> <BuildConfiguration Include="Debug"> <Key>Cfg_2</Key> <CfgParent>Base</CfgParent> </BuildConfiguration> <BuildConfiguration Include="Release"> <Key>Cfg_1</Key> <CfgParent>Base</CfgParent> </BuildConfiguration> </ItemGroup> <Import Project="$(BDS)\Bin\CodeGear.Delphi.Targets" Condition="Exists('$(BDS)\Bin\CodeGear.Delphi.Targets')"/> <ProjectExtensions> <Borland.Personality>Delphi.Personality.12</Borland.Personality> <Borland.ProjectType/> <BorlandProject> <Delphi.Personality> <Source> <Source Name="MainSource">Project21.dpr</Source> </Source> <Parameters> <Parameters Name="UseLauncher">False</Parameters> <Parameters Name="LoadAllSymbols">True</Parameters> <Parameters Name="LoadUnspecifiedSymbols">False</Parameters> </Parameters> <VersionInfo> <VersionInfo Name="IncludeVerInfo">False</VersionInfo> <VersionInfo Name="AutoIncBuild">False</VersionInfo> <VersionInfo Name="MajorVer">1</VersionInfo> <VersionInfo Name="MinorVer">0</VersionInfo> <VersionInfo Name="Release">0</VersionInfo> <VersionInfo Name="Build">0</VersionInfo> <VersionInfo Name="Debug">False</VersionInfo> <VersionInfo Name="PreRelease">False</VersionInfo> <VersionInfo Name="Special">False</VersionInfo> <VersionInfo Name="Private">False</VersionInfo> <VersionInfo Name="DLL">False</VersionInfo> <VersionInfo Name="Locale">1045</VersionInfo> <VersionInfo Name="CodePage">1250</VersionInfo> </VersionInfo> <VersionInfoKeys> <VersionInfoKeys Name="CompanyName"/> <VersionInfoKeys Name="FileDescription"/> <VersionInfoKeys Name="FileVersion">1.0.0.0</VersionInfoKeys> <VersionInfoKeys Name="InternalName"/> <VersionInfoKeys Name="LegalCopyright"/> <VersionInfoKeys Name="LegalTrademarks"/> <VersionInfoKeys Name="OriginalFilename"/> <VersionInfoKeys Name="ProductName"/> <VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys> <VersionInfoKeys Name="Comments"/> </VersionInfoKeys> </Delphi.Personality> </BorlandProject> <ProjectFileVersion>12</ProjectFileVersion> </ProjectExtensions> </Project> 

Thanks.

+4
source share
2 answers

When using conditional compilation, be sure to build after switching configurations. Apparently, the current set of β€œdefines” is not part of the key that was used to check whether some unit needs to be recompiled or not. If everything you changed is a definition (that is: DEBUG is no longer defined), the compiler simply does not know about it and continues to use the precompiled block.

But since we are talking about FastMM4, there is another way: you can define InstallOnlyIfRunningInIDE for DEBUG and RELEASE, and FastMM4 will not install its memory manager if you are not working with the IDE.


Edit

Given your late change, I assume your project configuration is to blame, because IFDEF works just fine. Inspect both branches of your configuration options, very much so that you don't have the "DEBUG" defined for both Release and Debug.

+6
source

It appears that DEBUG is defined in the base configuration (which should have general compilation settings). When you change Base, all unmodified settings default to Base.

Make sure you do not put DEBUG in the Base configuration instead of the Debug configuration by accident.

0
source

All Articles