delphi – 使用或不使用DEBUG条件定义
在使用Debug Build Configuration编译项目时,我有一个想法在FullDebugMode中使用FastMM4.
当我选择Debug构建配置时,Delphi会自动将DEBUG设置为条件定义.所以,这段代码应该按预期工作: 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; 它有效.但是,当我将构建配置更改为Release配置时.这段代码也有效!它不应该?由于不应定义DEBUG条件. 因此,有人可以解释为什么这个代码执行而不管构建配置如何以及如何正确设置它(以仅在使用调试配置时编译FastMM4的方式). 编辑后 使用FastMM只是一个例子.在发布我的问题之前,我已经在不同的情况下测试了它.这里是: 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. 无论构建配置如何,上面的代码都将编译.为什么? 第二次编辑后 我知道,其他人说我的例子按预期工作.但他们不适合我.我在Delphi 2010上检查了这个行为,它是完全相同的(仍然无法正常工作). 也许这会有所帮助:我用RELEASE替换了DEBUG指令,看看会发生什么.结果是RELEASE导致我的示例代码不会在两种配置中构建. 第三次编辑: 我的dproj文件: <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)BinCodeGear.Delphi.Targets" Condition="Exists('$(BDS)BinCodeGear.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> 谢谢. 解决方法
使用条件编译时,请确保在切换配置后始终进行构建.显然,当前的“定义”集合不是用于测试某个单元是否需要重新编译的密钥的一部分.如果您更改的是一个定义(即:不再定义DEBUG),编译器根本不知道它,并继续使用预编译单元.
但由于这是关于FastMM4,还有另一种方法:您可以为DEBUG和RELEASE定义InstallOnlyIfRunningInIDE,并且除非您从IDE运行,否则FastMM4将不会安装它的内存管理器. 编辑 鉴于你以后的编辑,我认为你的项目配置是罪魁祸首,因为IFDEF的工作很好.检查配置选项的两个分支,即没有为Release和Debug定义“DEBUG”. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |