首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

C++Builder2011的IdUDPServer控件的UDPRead事件函数保存解决办法

2012-03-13 
C++Builder2011的IdUDPServer控件的UDPRead事件函数保存报错的头文件://--------------------------------

C++Builder2011的IdUDPServer控件的UDPRead事件函数保存
报错的头文件:
//---------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <ExtCtrls.hpp>
#include "SHDocVw_OCX.h"
#include <OleCtrls.hpp>
#include <SHDocVw.hpp>
#include <IdBaseComponent.hpp>
#include <IdComponent.hpp>
#include <IdUDPBase.hpp>
#include <IdUDPClient.hpp>
#include <IdUDPServer.hpp>
//---------------------------------------
class TForm1 : public TForm
{
__published:// IDE-managed Components
TPageControl *PageControl1;
TTabSheet *TabSheet1;
TTabSheet *TabSheet2;
TPanel *Panel1;
TComboBox *ComboBox1;
TButton *Button1;
TLabel *Label1;
TWebBrowser *WebBrowser1;
TMemo *Memo1;
TMemo *Memo2;
TButton *Button2;
TButton *Button3;
TIdUDPClient *IdUDPClient1;
TIdUDPServer *IdUDPServer1;
void __fastcall Button1Click(TObject *Sender);
void __fastcall ComboBox1KeyUp(TObject *Sender, WORD &Key, TShiftState Shift);
void __fastcall IdUDPServer1UDPRead(TIdUDPListenerThread *AThread, TArray<System.Byte> AData,
  TIdSocketHandle *ABinding);
private:// User declarations
public:// User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------
#endif

红色部分报错:[BCC32 Error] Unit1.cpp(35): E2451 Undefined symbol 'TIdUDPListenerThread'
但我用右键转到定义,TIdUDPListenerThread类是在IdUDPServer.hpp头文件中定义的,能跳转过去,且该头文件在Unit1.h里已包含(蓝色部分)。
IdUDPServer.hpp对类TIdUDPListenerThread的定义内容如下:

C/C++ code
class PASCALIMPLEMENTATION TIdUDPListenerThread : public Idthread::TIdThread{    typedef Idthread::TIdThread inherited;    protected:    Idsockethandle::TIdSocketHandle* FBinding;    int FAcceptWait;    System::DynamicArray<System::Byte> FBuffer;    // System::TArray__1<System::Byte>  FBuffer;    System::UnicodeString FCurrentException;    System::TClass FCurrentExceptionClass;    System::TObject* FData;    TIdUDPServer* FServer;    virtual void __fastcall AfterRun(void);    virtual void __fastcall Run(void);    public:    __fastcall virtual TIdUDPListenerThread(TIdUDPServer* AOwner, Idsockethandle::TIdSocketHandle* ABinding);    __fastcall virtual ~TIdUDPListenerThread(void);    void __fastcall UDPRead(void);    void __fastcall UDPException(void);    __property int AcceptWait = {read=FAcceptWait, write=FAcceptWait, nodefault};    __property Idsockethandle::TIdSocketHandle* Binding = {read=FBinding};    __property TIdUDPServer* Server = {read=FServer};    __property System::TObject* Data = {read=FData, write=FData};};

请问为什么还报错?这都是C++Builder2011自己生产的代码啊!难道是C++Builder2011的Bug?盼高手解答

[解决办法]
这是Indy的Bug.解决方法是不要在IDE属性窗口中设置OnUDPRead,而动态设置,
先声明并定义:
void __fastcall IdUDPServer1UDPRead(TIdUDPListenerThread *AThread, TArray<System.Byte> AData,
TIdSocketHandle *ABinding);
再在比如Form的OnCreate事件中设置
IdUDPServer1->OnUDPRead=IdUDPServer1UDPRead;
[解决办法]
强制转换一下。
IdUDPServer1->OnUDPRead = (TUDPReadEvent)&IdUDPServer1UDPRead;

[解决办法]
好像最新版本是 Indy 10.5.8
[解决办法]
这不是Indy的问题,只是CBuilder2011(也就是CBuilder XE)的BUG实在太多了。
[解决办法]
是的,2010 + Up4,5相对稳定一些。

热点排行