Delphi 编译器警告指向 Delphi 自己的单元

发布于 2024-07-20 15:50:43 字数 591 浏览 12 评论 0原文

在 Delphi 2007 中,处理一个包含自定义组件的项目时,当我进行完整构建时(但不是当我进行直接编译时),我收到了这组警告作为消息中的前四个警告:

[DCC Warning] Dialogs.pas(1426): W1002 Symbol 'TFileOpenDialog' is specific to a platform
[DCC Warning] Dialogs.pas(1446): W1002 Symbol 'TFileSaveDialog' is specific to a platform
[DCC Warning] ComCtrls.pas(6757): W1036 Variable 'Section' might not have been initialized
[DCC Warning] ComCtrls.pas(19268): W1023 Comparing signed and unsigned types - widened both operands

我通常会尝试消除我可以在任何地方发出编译器警告,但这些是“库存”Delphi 单元。 这些警告是我的代码中某些内容的间接结果吗? 如果是这样,我如何找出什么/在哪里? 如果没有,我该怎么办?

In Delphi 2007, working on a project which includes a custom component, I'm getting this set of warnings as the first four in Messages when I do a full build (but not when I do a straight compile):

[DCC Warning] Dialogs.pas(1426): W1002 Symbol 'TFileOpenDialog' is specific to a platform
[DCC Warning] Dialogs.pas(1446): W1002 Symbol 'TFileSaveDialog' is specific to a platform
[DCC Warning] ComCtrls.pas(6757): W1036 Variable 'Section' might not have been initialized
[DCC Warning] ComCtrls.pas(19268): W1023 Comparing signed and unsigned types - widened both operands

I generally try to eliminate compiler warnings where I can, but these are "stock" Delphi units. Are these warnings the indirect result of something in my code? If so, how do I figure out what/where? If not, what should I do about them?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

春花秋月 2024-07-27 15:50:44

我花了很长时间才解决这些问题(好吧,无论如何,你的前两个问题),并且在我的无知中实际上卸载了 Delphi 并重新安装它但无济于事。 最后发现是由于项目设置不足导致的。 至少一开始,如果您从早期的 Delphi 迁移项目,您现有的项目设置会被转换,但没有明显的原因,Delphi 会开始忘记这一点,并为您提供一组“空白”项目设置。 您可以通过打开“项目选项”来查看这一点,您将在其中找到“基础”、“发布”和“调试”。 查看活动的路径(在项目管理器中以粗体显示),您应该看到它没有目录路径以及默认的所有提示和警告。 大多数默认值都很好,但应该禁用“平台符号”和“平台单元”(至少对于 Win32 来说)。
问候,
布莱恩

I spent ages getting these problems (well, your first two anyway) and in my ignorance actually uninstalled Delphi and reinstalled it to no avail. I finally found that it is caused by the lack of project settings. At least atfirst, if you migrate a projects from an earlier Delphi, your existing project settings get converted but for no apparent reason Delphi can start forgetting about this and gives you a 'blank' set of project settings. You can see this by opening Project-Options where you will find Base, Release and Debug. Check out the active one (it is bold in the project manager) and you should see that it has no directory paths as well as all hints and warnings at their defaults. Most of these defaults are fine but 'Platform Symbol' and 'Platform unit' should be disabled (at least for Win32 stuff).
Regards,
Brian

雾里花 2024-07-27 15:50:44

如果您想继续将 VCL 源显式编译到项目中,您可以制作引发编译器提示/警告的单元的副本,并“修复”该副本中的提示/警告。
将这些 VCL 单元的更新/“固定”副本放入另一个文件夹中,并确保将该文件夹的路径添加到项目的搜索路径中,位于 Delphi VCL 源代码的路径之前。

例如,我的项目搜索路径如下所示:“C:\Dev\Source\MyFixedVCLUnits;C:\Program Files\CodeGear\RAD Studio\6.0\source”

要给出删除这些警告所需的简单修复的示例,请在此处是 Dialogs.pas 中的功能之一,现在位于我的
“C:\Dev\Source\MyFixedVCLUnits”文件夹:

{$WARNINGS OFF}
函数 TFileOpenDialogWrapper.CreateFileDialog: TCustomFileDialog;
开始
结果 := TFileOpenDialog.Create(nil);
结果.OnExecute := OnExecuteEvent;
结束;
{$警告开启}

在这种情况下,只需根据需要添加 {$WARNINGS OFF} 等即可。

If you want to continue explicitly compiling the VCL source into your project you can make a copy of the units that are raising the compiler hints/warnings and "fix" the hints/warnings in that copy.
Put the updated/"fixed" copies of those VCL units in another folder and make sure you add the path to that folder to your project's Search path BEFORE the path to the Delphi VCL source.

E.g. my project search path looks something like this: "C:\Dev\Source\MyFixedVCLUnits;C:\Program Files\CodeGear\RAD Studio\6.0\source"

To give an example of the simple fixes required to remove these warnings, here is one of the functions in the Dialogs.pas that now lives in my
"C:\Dev\Source\MyFixedVCLUnits" folder:

{$WARNINGS OFF}
function TFileOpenDialogWrapper.CreateFileDialog: TCustomFileDialog;
begin
Result := TFileOpenDialog.Create(nil);
Result.OnExecute := OnExecuteEvent;
end;
{$WARNINGS ON}

In this case, just add the {$WARNINGS OFF} etc as required.

我恋#小黄人 2024-07-27 15:50:44

TFileOpenDialog 仅适用于 Windows Vista 及更高版本。 您应该使用 TOpenDialog 而不是 TFileOpenDialog,在较新的 Delphi 版本中,它将检测正在运行的操作系统并显示正确的对话框。
https://forums.embarcadero.com/thread.jspa?threadID=70498

TFileOpenDialog will work only on Windows Vista and up. You should use TOpenDialog instead of TFileOpenDialog, in newer Delphi versions it will detect what OS it is running and display proper dialog.
https://forums.embarcadero.com/thread.jspa?threadID=70498

⊕婉儿 2024-07-27 15:50:44

如果您只针对特定平台开发开放项目源码并添加

{$WARN SYMBOL_PLATFORM OFF}

If you develop only for specific platform open project source and add

{$WARN SYMBOL_PLATFORM OFF}
几度春秋 2024-07-27 15:50:44

可以在“Delphi Compiler | Delphi Compiler”下的项目选项中单独禁用编译器警告(根据警告类型单独禁用)。 提示和警告'

Compiler warnings can be disabled individually (separate per warning type) in the project options under 'Delphi Compiler | Hints and Warnings'

梦在深巷 2024-07-27 15:50:43

我相信这是因为你的构建路径中有库存的 Delphi 源代码。 如果删除 Delphi 源目录,那么构建时应该不会出现这些警告。

I believe it is because you have the stock Delphi source in your build path. If you remove the Delphi source directories, then it should build without these warnings.

我一直都在从未离去 2024-07-27 15:50:43

它们仅在执行构建时显示的原因是编译命令仅编译自上次编译以来已更改的源。 而“构建”命令会重新编译项目中的所有内容,无论发生什么变化。

这些警告很可能是由项目搜索路径中包含的 Delphi 源文件夹引起的。 删除它并删除项目文件夹中的 dcus 将告诉您重新编译时项目中的任何内容是否需要 Delphi 源代码。 根据我的经验,如果您在 Delphi 的实现中发现了错误并制作了 Delphi 类的自定义副本来更正该错误,则您应该需要 Delphi 源代码。 如果是这种情况,当您尝试在没有 Delphi 源代码的情况下构建时,您通常会得到:

单元“%s”与单元“%s”一起编译
在“%s”中,但版本“%s”不同
发现(F2446)

其中 %s 将是一些低级别的 Delphi 类。

如果您没有收到任何错误,那么它实际上并不需要 Delphi 源代码。

如果 Delphi 源代码位于环境搜索路径中,也会发生这种情况。

The reason they show up only when doing a Build is that the compile command only compiles source which has changed since the previous compile. While the Build command recompiles everything in the project regardless of changes.

The warnings are most likely caused by the Delphi source folder being included in the project search path. Removing it and deleting the dcus in your project's folder will tell you if anything in the project required the Delphi source when you recompile. In my experience you should need the Delphi source if you have found a bug in Delphi's implementation and made a custom copy of a Delphi class to correct the bug. If this is the case when you try to build without the Delphi source you will usually get:

Unit '%s' is compiled with unit '%s'
in '%s' but different version '%s'
found (F2446)

Where %s will be some low level Delphi class.

If you don't get any error's it didn't really need the Delphi source.

This can also happen if the Delphi source is in the environment search path.

梦里泪两行 2024-07-27 15:50:43

您提到的前两个警告(以及其他一些警告)是为了让您意识到您当前使用的代码无法跨 Delphi 支持的不同平台进行编译。 对于 Delphi 2007,没有太多内容,但它带有 Kylix(已消失的 Linux 版本)和 Delphi for .NET(也已消失)的残余部分。

Delphi 的最新版本支持跨平台(Win32/Win64、OS X、iOS 和 Android),在开发 Firemonkey 应用程序(或 VCL 应用程序,如果 Win32 和 Win64 之间存在差异)时,这些消息再次相关。 它们指示您的代码中必须针对不同操作系统对代码进行调整的点。 (例如,您引用的两个对话框适用于特定于 Windows 的对话框;您需要根据目标平台使用不同的对话框,并在平台区域周围使用 {$IFDEF} 语句-特定于防止它们被编译为其他平台。

由于您当前的代码无法直接(即使在现代 Delphi 版本中)移植到 Windows 以外的任何平台,因为它是基于 VCL 的,因此您可以安全地关闭这些警告。使用Project->Options->Compiler Messages,并取消选中以下消息(或使用我已包含在您的代码中的编译器定义):

Library Symbol                       {$WARN SYMBOL_LIBRARY OFF}
Platform Symbol                      {$WARN SYMBOL_PLATFORM OFF}
Library Unit                         {$WARN UNIT_LIBRARY OFF}
Platform Unit                        {$WARN UNIT_PLATFORM OFF}
Unsafe type  (.NET remnant)          {$WARN UNSAFETYPE OFF}
Unsafe code  (.NET remnant)          {$WARN UNSAFECODE OFF}
Unsafe typecast (.NET remnant)       {$WARN UNSAFECAST OFF}

您提到的最后两个我不能使用 D2007(IDE 版本 11.0.2804.9245)重现,所以我怀疑 skamradt 的答案是正确的 - 这是因为你的搜索路径中有 VCL 源目录,并且你不应该将其设置为 $ 。 (BDS)\Lib 如果您需要能够单步调试源代码,请使用 Project->Options->Compiler 页面,并选中 Use debug相反,调试 下的 DCUs 选项。

The first two warnings you mention (along with a few others) are to make you aware that the code you're currently using won't compile across different platforms Delphi supports. For Delphi 2007, there isn't much, but it carries the remnants of Kylix (the Linux version that's gone) and Delphi for .NET (which is also gone).

More recent versions of Delphi support cross-platform (Win32/Win64, OS X, iOS, and Android), where these messages are relevant again when developing Firemonkey applications (or VCL apps if there are differences between Win32 and Win64). They indicate the points in your code where you will have to make adjustments in your code for different operating systems. (For instance, the two you cite are for Windows-specific dialogs; you'd need to use a different dialog based on the target platform, and use {$IFDEF} statements around the areas that are platform-specific to keep them from being compiled in for other platforms.

As your current code can't be ported directly (even in a modern Delphi version) to anything other than Windows because it's VCL-based, you can safely turn off those warnings. Use Project->Options->Compiler Messages, and uncheck the following messages (or use the compiler define I've included in your code):

Library Symbol                       {$WARN SYMBOL_LIBRARY OFF}
Platform Symbol                      {$WARN SYMBOL_PLATFORM OFF}
Library Unit                         {$WARN UNIT_LIBRARY OFF}
Platform Unit                        {$WARN UNIT_PLATFORM OFF}
Unsafe type  (.NET remnant)          {$WARN UNSAFETYPE OFF}
Unsafe code  (.NET remnant)          {$WARN UNSAFECODE OFF}
Unsafe typecast (.NET remnant)       {$WARN UNSAFECAST OFF}

The last two you've mentioned I can't reproduce with D2007 (IDE version 11.0.2804.9245), so I'd suspect that skamradt's answer is correct - it's because you have the VCL source directories in your search path, and you shouldn't. It should be set to $(BDS)\Lib. If you need to be able to step through the source, use the Project->Options->Compiler page, and check the Use debug DCUs option under Debugging instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文