Reputation: 6979
I had an idea to use FastMM4 in FullDebugMode when compiling my project with Debug Build Configuration.
When I chose the Debug build configuration the Delphi automatically sets up DEBUG as a conditional define. 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 build configuration to the Release configuration. This code also works! And it should not? Since the DEBUG conditional should not be defined.
So, could somebody explain me why this code executes regardless of the build configuration and how to setup it properly (in a way that FastMM4 would be compiled only when using debug configuration).
After Edit
With FastMM it was only an example. Before posting here my question I've tested it on different case. Here it 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 no matter of build configuration. Why?
After second edit
I know, that others saying that my examples are working as expected. But they are not working for me. I've checked this behaviour on Delphi 2010 and it is identical (still not working).
Maybe this will be helpful: I've replaced DEBUG
directive with RELEASE
to see what will happen. The result was that RELEASE
causes that my example code will 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>
Thank you.
Upvotes: 4
Views: 3123
Reputation: 3820
Appears that DEBUG is defined on Base configuration (which is supposed to have the common compilation settings). When you change Base, all non-modified settings default to Base values.
Verify if you doesn't put DEBUG on Base configuration instead of Debug config by accident.
Upvotes: 0
Reputation: 25678
When using conditional compilation, make sure you always do a build after switching configurations. Apparently the current set of "defines" is not part of the key that's used to test if a certain unit needs recompilation or not. If all you changed is a define (ie: DEBUG is no longer defined), the compiler simply doesn't know about it, and keeps using the pre-compiled unit.
But since this is about FastMM4, there's an other way: You can define InstallOnlyIfRunningInIDE
for both DEBUG and RELEASE and FastMM4 will not install it's memory manager unless you're running from the IDE.
Given your later edit, I assume your project's configuration is to blame, because IFDEF's work just fine. Inspect both branches of your configuration options, very that you don't have "DEBUG" defined for both Release and Debug.
Upvotes: 6