Home > Net >  Compiler error "E2003 Undeclared identifier"
Compiler error "E2003 Undeclared identifier"

Time:03-01

In this code:

uses 
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, 
  Forms, Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, 
  IdTCPClient, IdIOHandler, IdGlobal, StdCtrls;

function WaitForCommand(args: Pointer): Cardinal; stdcall;
begin
  while client.Connected do
    if not HandleResponse(client.IOHandler) then
      break;
  Result := 0;
end;

I have this error:

[DCC Error] Unit1.pas(159): E2003 Undeclared identifier: 'HandleResponse'

CodePudding user response:

How to understand messages?

Let's read it in parts:

  1. [DCC Error]

    DCC is the Delphi Compiler, so it is about our code, not about linking or packaging.

  2. Unit1.pas

    The file in which the error occurred. Normally Delphi's editor automatically display this file to you.

  3. (159)

    The line in which an error occurred. Normaly Delphi's editor automatically puts your text cursor into this line.

  4. E2003

    That's is the code of the error in case any further text is unavailable. It is like HTTP's status 404 is a code (with the actual text "Not Found" for it) or like a traffic's light red is a code (without any further text telling you to stop).

  5. Undeclared identifier:

    At this point the compiler does not know how to interpret what is now named. And and even cannot tell you if it is a missing function, a missing type, or else - hence the overall term "identifer".

  6. 'HandleResponse'

    Normally Delphi's editor automatically puts your text cursor in the line of issue at the start of the text that cannot be understood.

What could you do?

It is undeclared. Declare it. However, only you can know what you want. You could

  • declare a type:
    type
      HandleResponse= Boolean;
    
  • define a function:
    function HandleResponse(h: TIdIOHandler): Boolean;
    begin
      result:= FALSE;
    end;
    
  • import a function from a DLL:
    function HandleResponse(p: Pointer): LongBool; stdcall; external 'any.dll';
    
  • add the unit that might already have it:
    uses
      WhatIsMissingSoFar;
    

...or do other things I yet have to remember. But I'm sure you understand that in these 3 examples the identifier HandleResponse is now declared. I don't have to tell you that declarations must be done before using it, right?

  • Related