Why Delphi says 'cannot resolve unit name xxx&

2019-02-16 11:59发布

问题:

I'm working with Delphi2010 Enterprise Update 4.
When I'm opening my project in the IDE and displaying the mainform code, there are 2 unit names underline in red.

xxx http://img268.imageshack.us/img268/6475/unitnameunresolved.png.

I have verified that the path to the unit source is in the Library path and in the Browsing path.

Surprisingly, when I'm doing a right-clicking on the unit and selecting Open file at cursor, it works (ie. delphi opens the right unit).

Any idea about that ?

回答1:

Error Insight which keeps all the error messages into the structure view is quite buggy. It doesn't understand your code the way the compiler understands it.

There is an IDE Fix Pack developed by Andreas Hausladen which reduces the number of those "Cannot resolve unit xyz" problems.

It doesn't fix the bug, but it makes them less visible by addressing some of the Error Insight's threading problems.



回答2:

Out of curiosity, is there any code in AdPort and/or AdStatLt that is subject to conditional compilation ?

The parser that underpins Error Insight is I think different (physically and contextually) from the compiler. The compiler may be able to make sense of those conditional compilation areas that Error Insight is not.

This is just speculation on my part, but Error Insight is much improved in Delphi 2010 and typically now only chokes when there are errors in my code that I have yet to resolve.



回答3:

Closing and reopening a project usually helps to get rid of most of these errors. Try it...

(That doesn't change the fact that nowadays, this is probably my number one annoyance in the IDE...)



回答4:

I reset the library path under tools\options\environment options\delphi options\library.

Click the dropdown box, and reselect your os, and it will reset the path to the library. Worked for me.