-3

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'

AmigoJack
  • 5,234
  • 1
  • 15
  • 31
MrCamarium
  • 5
  • 1
  • 5
  • This is simply because you haven't declared any function named `HandleResponse`, or because you haven't included the right unit in the `uses` clauses. – Andreas Rejbrand Feb 22 '22 at 07:30
  • uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdIOHandler, IdGlobal, StdCtrls; – MrCamarium Feb 22 '22 at 09:00
  • The problem is that `HandleResponse` isn't a function that comes with Delphi. It is a function you must write yourself! – Andreas Rejbrand Feb 22 '22 at 09:27
  • 2
    This is a bit like asking your butler, "Please give me my frogumator." without first telling your butler what your "frogumator" *is*, and then becoming angry with the poor butler for not understanding your request. – Andreas Rejbrand Feb 22 '22 at 09:42
  • How should I write it? What can I provide you to help me out? – MrCamarium Feb 22 '22 at 14:38
  • I have no idea. If your app is a server that controls traffic lights, your `HandleResponse` maybe should change a light from red to green. Or if your app is a media server, maybe the command is to pause the current playback. Your only option is to hire a computer programmer to write the program (and of course you must also tell him the application's specification and requirements). Computer programs cannot write themselves (yet). – Andreas Rejbrand Feb 22 '22 at 14:45
  • Where have you got the code from? Prpbably you'll find your `HandleResponse` there too. – Uli Gerhardt Feb 23 '22 at 08:02
  • Solved I defined the function. – MrCamarium Feb 23 '22 at 08:59

1 Answers1

4

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?

AmigoJack
  • 5,234
  • 1
  • 15
  • 31