Answer the question
In order to leave comments, you need to log in
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;
[bcc32 Error] AddDevice.cpp(489): E2034 Cannot convert 'TIdTelnetDataAvailEvent' to 'TIdTelnetDataAvailEvent'
class TAddDeviceDialog : public TForm
{
__published: // IDE-managed Components
private: // User declarations
TIdTelnet *ScanIdTelnet;
void __fastcall IdTelnetDataAvailable(TIdTelnet *Sender, const TIdBytes Buffer);
public: // User declarations
};
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 questionAsk a Question
731 491 924 answers to any question