Pascal Delphi - Undeclared Identifier
Asked Answered
L

1

1

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.

Lehet answered 31/1, 2014 at 15:36 Comment(1)
Can you compile the program? Is the error a compilation error or an IDE insight error?Shorter
O
10

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.

Oppen answered 31/1, 2014 at 16:3 Comment(8)
I'll try the second optionLehet
@JamEngulfer221: You're a glutton for punishment. :-) You did see the list of negatives, as well as the note about it not being useful anyway, right?Oppen
I do it the second way FWIW. I hate relying on search paths. To each their own though.Shorter
Lets all hope that they fix it in XE6. Error Insight is a joke.Johnathanjohnathon
@David: I didn't say a thing about relying on search paths. I said the stupid wavy red underlines get annoying. I still add things to the project file when they should be, but the error insight window replacing the structure window and the red underlines in the code editor are just irritating. (I really do wish you would start reading the words I actually write, instead of inventing them.)Oppen
I guess I don't understand then. If the files aren't in the project, and they aren't located using search path, how are they found?Shorter
@David: The standard VCL files are located exactly where the IDE already knows about them, and files that should be added to the project file are in fact added. I have a common shared units folder (addressed with a relative path) for units that are common across multiple applications, which is in the search path. Everything works perfectly well, and has survived the transition across replacing machines now several times without a single glitch.Oppen
Ah, I'm just putting all of the units into the project source folder. I'm not too fussed about reusabilityLehet

© 2022 - 2024 — McMap. All rights reserved.