I
I
Igor Ivanov2016-02-08 21:31:10
C++ / C#
Igor Ivanov, 2016-02-08 21:31:10

How to assign an event handler to a dynamically created Internet Direct (Indy) component?

Development environment - Embarcadero® C++Builder 10 Seattle.
Dynamically creating a TIdTelnet component:
TIdTelnet *ScanIdTelnet=new TIdTelnet(this);
According to the documentation from indyproject.org, to assign a handler to the OnDataAvailable event, you need to assign a function to this property that handles this event.
I do it like this:

// создаю функцию для обработки события
TIdTelnetDataAvailEvent IdTelnetDataAvailable(TIdTelnet *Sender, const TIdBytes Buffer)
{
  // тут что-то делаем с данными из Buffer
}
// назначаю
ScanIdTelnet->OnDataAvailable=IdTelnetDataAvailable;

When compiling, it swears:
[bcc32 Error] AddDevice.cpp(489): E2034 Cannot convert 'TIdTelnetDataAvailEvent' to 'TIdTelnetDataAvailEvent'

What am I doing wrong? How to do it right?
Update:
Understood. We do this:
In the class of the parent component (form), we write:
class TAddDeviceDialog : public TForm
{
__published:	// IDE-managed Components

private:	// User declarations
  TIdTelnet *ScanIdTelnet;
  void __fastcall IdTelnetDataAvailable(TIdTelnet *Sender, const TIdBytes Buffer);

public:		// User declarations

};

In a programme:
void __fastcall TAddDeviceDialog::StartScanButtonClick(TObject *Sender)
{
  ScanIdTelnet=new TIdTelnet(this);
        ScanIdTelnet->Host=sIP;
  ScanIdTelnet->OnDataAvailable=IdTelnetDataAvailable;
        try
  {
    ScanIdTelnet->Connect();
  }
  catch (EIdException &exception)
  {
           //sError=exception.Message; // Текст ошибки
  }
}

// обработчик OnDataAvailable 
void __fastcall TAddDeviceDialog::IdTelnetDataAvailable(TIdTelnet *Sender, const TIdBytes Buffer)
{
  // тут что-то делаем с данными из Buffer
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question