Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi compiler warnings pointing to Delphi's own units

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?

like image 356
Jamo Avatar asked May 15 '09 21:05

Jamo


4 Answers

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.

like image 188
skamradt Avatar answered Oct 22 '22 16:10

skamradt


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.

like image 6
Kenneth Cochran Avatar answered Oct 22 '22 16:10

Kenneth Cochran


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.

like image 3
Ken White Avatar answered Oct 22 '22 16:10

Ken White


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

like image 2
Brian Frost Avatar answered Oct 22 '22 16:10

Brian Frost