Pascal Delphi-未声明的标识符 [英] Pascal Delphi - Undeclared Identifier

查看:294
本文介绍了Pascal Delphi-未声明的标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Delphi项目中使用Synapse库进行一些联网.

当我尝试使用外部单元中定义的一种类型(即"TTCPBlockSocket")时,它带有红色下划线,并显示"Undeclared Identifier'TTCPBlockSocket'".

文件全部位于正确的文件夹中,并且"uses"语句可以找到它们,并且不显示任何错误.

奇怪的是,我在另一个项目中进行了相同的设置,并且该项目中没有错误.

请注意:我无法安装/编辑软件/设置,因此无法添加任何修复程序.

解决方案

这是错误洞察.自从Error Insight在Delphi 2005或2006中首次引入以来,它就一直存在,直到今天在Delphi XE5中仍然存在.

这是由用于Error Insight的不同编译器引起的,显然,该编译器无法访问Code Insight编译器(可帮助您在代码编辑器中查找符号的代码)所使用的同一符号集.行编译器(用于实际为应用程序或程序包编译代码的编译器).因此,它仅使用项目(.dpr)文件中实际引用的文件来定位符号,并且由于代码中uses子句中的大多数文件不在.dpr中,因此无法找到它们./p>

有两种修复方法(一种很简单,一种可行,但背面很痛苦):

  1. (简单的一种).在工具"->选项"的编辑器选项"部分的代码洞察"中,完全关闭Error Insight;只需取消选中Error Insight框即可.我之所以喜欢这个选项,是因为Error Insight仍然无法正常工作,并且避免了每10分钟必须使用另一个选项的麻烦.这是我安装新版本的IDE并看到红色下划线时要做的第一件事.

  2. (痛苦的方式).对于包含下划线符号之一的每个单元,请使用项目"->添加到项目".这会将对每个单元的引用添加到项目.dpr文件,这将导致其大小急剧增加.这很痛苦,因为您通常必须为尚未添加的每个单个单元(包括我的经验,包括那些属于标准VCL/RTL的单元)执行此操作变得烦人.错误洞察力并没有告诉你,IMO不能快速使用 Ctrl + F9 .

I'm using the Synapse library in a Delphi project to do some networking.

When I try and use one of the Types that are defined in the external units, i.e: 'TTCPBlockSocket', it has the red underline and says "Undeclared Identifier 'TTCPBlockSocket'".

The files are all in the correct folders and the 'uses' statement can find them and shows no errors.

The strange thing is that I've had an identical setup in another project and there have been no errors in that project.

As a note: I can't install/edit the software/settings, so I can't add any fixes.

解决方案

This is a well-known bug in Error Insight. It has existed since Error Insight was first introduced in Delphi 2005 or 2006, and still exists today in Delphi XE5.

It's caused by a different compiler being used for Error Insight, apparently, that doesn't have access to the same symbol set used by the Code Insight compiler (the one that helps you find symbols in the Code Editor) or the command-line compiler (the one used to actually compile your code for an application or package). It therefore only uses files that are actually referenced in the project (.dpr) file to locate symbols, and since the majority of files in the uses clause in your code aren't in the .dpr, it can't find them.

There are two fixes (one that is very easy, and one that works but is a pain in the backside):

  1. (The easy one). Turn off Error Insight totally, in Tools->Options, the Editor Options section, Code Insight; just uncheck the box for Error Insight. I prefer this one because Error Insight doesn't work properly anyway, and it avoids the annoyance of having to use the other option every 10 minutes. This is the first thing I do when I install a new version of the IDE and see the red underlines.

  2. (The pain way). Use Project->Add to project for every unit that contains one of the underlined symbols. This adds a reference to every unit to the project .dpr file, which causes it to increase in size drastically. It's a pain because you typically have to do that for every single unit (in my experience, including those that are part of the standard VCL/RTL) that hasn't already been added, and it very quickly becomes irritating. Error Insight doesn't tell you anything that a quick Ctrl+F9 won't anyway, IMO.

这篇关于Pascal Delphi-未声明的标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆