Cry about...
Delphi Troubleshooting


Undeclared identifier: 'XXXX'

(or which unit do I need for type X?)


Symptom:

When compiling a unit the compiler generates the following error:

[Error] MyUnit.pas(LL): Undeclared identifier: 'NNNN'

where:

MyUnit.pas Is the Delphi source file.
LL Is the line number in the file.
NNNN Is the name of the identifier.

Cause:

The compiler does not recognise the identifier 'NNNN'. This is either because the identifier is miss-spelt or because the compiler could not find a corresponding definition.

Remedy:

  • The most common cause is a simple misspelling where the identifier is used. For example:
var number: Integer;
begin
    numbr := 1;

Here the identifier is defined as 'number' but used in the code as 'numbr'. The solution is to correct the spelling. This is the error scenario dealt with in the Delphi online help.

  • Another common cause is that the code is correct but that the necessary unit has not been included in the uses clause. For example:
try
  .
  .
except
on E: Exception do
  .
[Error] Undeclared identifier: 'Exception'

the code is correct but in this example, the unit 'SysUtils' was not included.

The following table (which is not exhaustive) lists types and functions (but generally not constants) together with the unit required:

Type Unit
_Stream ADODB_TLB
akTop, akLeft, akRight, akBottom Controls
AnsiLowerCase SysUtils
Application (the variable not a type) Forms
Beep SysUtils or Windows (different functions)
CGID_EXPLORER ShlObj
CN_BASE Controls
CoInitialize ActiveX
CopyFile Windows
CoUnInitialize ActiveX
CreateComObject ComObj
CreateOleObject ComObj
Date SysUtils
DeleteFile SysUtils or Windows (different versions)
DispatchInvokeError ComObj
DWORD Windows
EDatabaseError DB
EncodeDateTime DateUtils
EnumWindows Windows
EOleError ComObj
EOleException ComObj
EOleSysError ComObj
Exception SysUtils
ExtractFileName SysUtils
FileExists SysUtils
FileOpen SysUtils
FILETIME Windows
FindFirst SysUtils
FindFirstFile Windows
FindWindow Windows
FlushFileBuffers Windows
fmOpenRead SysUtils
fmShareDenyWrite SysUtils
Format SysUtils
FormatDateTime SysUtils
FreeAndNil SysUtils
fsBold Graphics
ftWideString DB
ftString DB
GetCurrentProcessId Windows
GetEnvironmentVariable SysUtils or Windows (different versions)
GetFileAttributes Windows
GetFileVersionInfoSize Windows
GetStdHandle Windows
GetTickCount Windows
GetWindowLong Windows
GlobalAddAtom Windows
HDC Windows
HFont Windows
HINTERNET WinInet
HKEY_CURRENT_USER Windows
HWND Windows
IHTMLDocument2 MSHTML or MSHTML_TLB
IHTMLElement MSHTML or MSHTML_TLB
IHTMLElementCollection MSHTML or MSHTML_TLB
IHTMLEventObj MSHTML or MSHTML_TLB
IID_IWebBrowser2 SHDocVw or SHDocVw_TLB
IMessage CDO_TLB
InternetClosehandle WinInet
InternetOpenUrl WinInet
InternetReadFile WinInet
IntToHex SysUtils
IntToStr SysUtils
IOleCommandTarget ActiveX
IOleContainer ActiveX
IOleInPlaceActiveObject ActiveX
IPersistStreamInit ActiveX
IsSameDay DateUtils
IStream ActiveX
IWebBrowser SHDocVw or SHDocVw_TLB
IWebBrowser2 SHDocVw or SHDocVw_TLB
LockWindowUpdate Windows
Log10 Math
LowerCase SysUtils
LPSTR Windows
MAX_PATH Windows
MessageBox Windows
MessageDlg Dialogs
MB_YESNO, MB_OK etc Windows
MinutesBetween DateUtils
Now SysUtils
OleInitialize ActiveX
OleUninitialize ActiveX
PItemIDList ShlObj
POleCmd ActiveX
POleCmdText ActiveX
PostMessage Windows
PosX StrUtils
QueryHighPerformanceCounter Windows
QueryPerformanceCounter Windows
RandomRange Math
RegisterHotKey Windows
ReverseString StrUtils
RoundTo Math
SendMessage Windows
SetForegroundWindow Windows
ShellExecute ShellAPI
ShellExecuteEx ShellAPI
SHGetFileInfo ShellAPI
SHFILEINFO ShellAPI
ShowMessage Dialogs
Sleep SysUtils
StrAlloc SysUtils
StrPas SysUtils
StrToDate SysUtils
StrToInt SysUtils
StrToIntDef SysUtils
TAdoConnection ADODB
TAdoQuery ADODB
TAlign Controls
TAlignment Classes
TAnchors Controls
TBitmap Graphics
TBlobStream DBTables
TCanvas Graphics
TClientSocket ScktComp
TComboBox StdCtrls
TComponent Classes
TControl Controls or QControls
TCriticalSection SyncObjs
TField DB
TFieldType DB
TFileName SysUtils
TFileStream Classes
TForm Forms
TFrame Forms
TGroupBox StdCtrls
TIID ActiveX
TIniFile IniFiles
TJPEGImage Jpeg
TLabel StdCtrls
TList Classes
TMemo StdCtrls
TMemoryStream Classes
TMouseButton Controls
TNofityEvent Classes
TObjectList Contnrs
TOSVersionInfo Windows
TPanel ExtCtrls
TPoint Types
TProcessEntry32 TlHelp32
TProgressBar ComCtrls or QComCtrls
TRadioButton StdCtrls
TRadioGroup ExtCtrls
TRect Types
TRegistry Registry
Trim SysUtils
TRoundToRange Math
TSearchRec SysUtils
TSize Windows
TSocketAddrIn Winsock
TStaticText StdCtrls
TStream Classes
TStringList Classes
TStrings Classes
TStringStream Classes
TSystemTime Windows
TTable DBTables
TTabSheet ComCtrls
TThread Classes
TTreeNode ComCtrls
TWebBrowser SHDocVw or SHDocVw_TLB
TWinSocketStream ScktComp
TWMCommand Messages
Unassigned Variants
VarArrayCreate Variants
VarArrayOf Variants
VirtualProtect Windows
VK_SNAPSHOT Windows
WaitForSingleObject Windows
WM_MOVE Messages
WM_MOVING Messages
WM_USER Messages
YearOf DateUtils

Later versions of Delphi have better online help and depending on the version of Delphi installed the required unit may be clear from the on-line help.

I will add to this table over time. If you know of any types that are missing that you would like to see included then please e-mail these to brian@cryer.co.uk.


These notes are believed to be correct for Delphi 6 and Delphi 7, and may apply to other versions as well.



About the author: is a dedicated software developer and webmaster. For his day job he develops websites and desktop applications as well as providing IT services. He moonlights as a technical author and consultant.