具体情况是想做个TComm的组件,TComm组件定义了一个Tbuf组件对象RecvBuf,TBuf具有一些事件,
比如OnBufAlreadyFull,TBuf数据满的时候触发次事件。现在需要在Comm的组件里也定义一个事件
OnRecvBufAlreadyFull,接收数据满的时候触发次事件,要怎么实现呢?
3 个解决方案
#1
//定义,通常写在.h头文件中
class TComm:public TComponent
{
...
private:
Tbuf *RecvBuf;
...
private:
//property OnBufAlreadyFull read
TBufAlreadyFullMethod __fastcall GetOnBufAlreadyFull(void);
//property OnBufAlreadyFull write
void __fastcall SetOnBufAlreadyFull(TBufAlreadyFullMethod Value);
...
__published:
__property TBufAlreadyFullMethod OnBufAlreadyFull = {read = GetOnBufAlreadyFull,write = SetOnBufAlreadyFull};
...
};
...
//实现,通常写在.cpp中
...
TBufAlreadyFullMethod __fastcall TComm::GetOnBufAlreadyFull(void)
{
return RecvBuf->OnBufAlreadyFull;
}
void __fastcall TComm::SetOnBufAlreadyFull(TBufAlreadyFullMethod Value)
{
RecvBuf->OnBufAlreadyFull = Value;
}
...
#2
up
#3
直接把事件指针作为函数的返回值或者参数。
太感谢一楼了。
太感谢一楼了。
#1
//定义,通常写在.h头文件中
class TComm:public TComponent
{
...
private:
Tbuf *RecvBuf;
...
private:
//property OnBufAlreadyFull read
TBufAlreadyFullMethod __fastcall GetOnBufAlreadyFull(void);
//property OnBufAlreadyFull write
void __fastcall SetOnBufAlreadyFull(TBufAlreadyFullMethod Value);
...
__published:
__property TBufAlreadyFullMethod OnBufAlreadyFull = {read = GetOnBufAlreadyFull,write = SetOnBufAlreadyFull};
...
};
...
//实现,通常写在.cpp中
...
TBufAlreadyFullMethod __fastcall TComm::GetOnBufAlreadyFull(void)
{
return RecvBuf->OnBufAlreadyFull;
}
void __fastcall TComm::SetOnBufAlreadyFull(TBufAlreadyFullMethod Value)
{
RecvBuf->OnBufAlreadyFull = Value;
}
...
#2
up
#3
直接把事件指针作为函数的返回值或者参数。
太感谢一楼了。
太感谢一楼了。