Delphi 2007 和 {$IFDEF...} 指令,无法看到我们的条件
我们的代码库中的组件文件中有以下内容:
{$IFDEF ADO}
FDatabase : TADODatabase;
{$ELSE}
FDatabase : TODBCDatabase;
{$ENDIF}
原因是,对于各种遗留应用程序,将使用一种或另一种类型的数据库连接和一组类。
然而,在配置新机器时,似乎我们的条件没有被考虑在内。 在项目设置中,它显示“ADO;DEBUG”,但它却使用 odbc 类型编译上述代码。
奇怪的是,它并不一致。 作为同一项目的一部分构建的两个不同的单元使用单独的设置。 换句话说,在一个地方我们的条件是可见的,而在另一个地方却不是。
编译错误的文件没有任何{$UNDEF或类似的指令,也不包含任何文件。
我在这里缺少什么?
已解决(呃):是的,Delphi 只是很愚蠢,或者诸如此类。
我们发现了这些:
两者都提到了“Platform=BNB”设置。 通过启用诊断输出,我们可以看到确切的值。 所以我们尝试根据文章重写它,但不走运,仍然是 BNB。 然后我们进入项目设置,结果发现它也可以在那里被覆盖,所以我们也这样做了,但仍然没有运气。
事实证明,Delphi 安装程序或其他什么在操作系统级别添加了一个“Platform=BNB”环境变量,删除它,重新启动 Delphi,一切都很好。
嗯,也是可以预料到的。 但我们仍然必须使用 Delphi。
We have the following in our codebase, in a component file:
{$IFDEF ADO}
FDatabase : TADODatabase;
{$ELSE}
FDatabase : TODBCDatabase;
{$ENDIF}
The reason is that for various legacy applications, one or the other type of database connection and set of classes is to be used.
However, while configuring a new machine, it seems that our conditionals aren't taken into account. In the project settings, it says "ADO;DEBUG", and yet it compiles the above code with the odbc type instead.
The odd thing is that it isn't consistent. Two different units built as part of the same project uses separate settings. In other words, in one place our conditional is visible, in another it is not.
The file that compiles wrong does not have any {$UNDEF or similar directives, nor does it include any files.
What am I missing here?
Solved (ugh): Right, Delphi is just being boneheaded, or whatnot.
We found these:
- I get “F1026 File not found”, OR some compiler options are not passed to the compiler from the IDE.
- Configuration='Debug' Platform='BNB'
Which both mention the "Platform=BNB" setting. By enabling the diagnostic output, we see that exact value. So we try to override it per the articles, no luck, still BNB. Then we go to the project settings, turns out it can be overriden there as well, so we do that too, still no luck.
Turns out the Delphi installer, or whatnot, has added a "Platform=BNB" environment variable on operating system level, removing that, restarting Delphi, and all is well.
Well, as well as can be expected. We still have to use Delphi though.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您更改这些条件时,您应该始终进行“构建所有”。
You should always make a "build all" when you change those conditions.
可能有一个单元实际上没有重新编译。 检查以下内容:
每当我遇到这样的问题时,我都会强力删除项目和组件文件夹中的每个 .dcu 文件,以防“全部构建”无法删除所有陈旧的 .dcus。 以下重新编译可以解决问题或显示是否使用了错误的 .dcu。
It could be that one unit is actually not re-compiled. Check the following:
Whenever I encounter problems like this I brute-force delete every .dcu file in my project and component folders just in case the "Build all" doesn't remove all stale .dcus. The following recompile either solves the problem or reveals if any wrong .dcu was used.