关于消息处理问题
问题描述:
我在一个程序中使用一个窗口使用下面的代码没错误,但当我有多个窗口时,就无法编译
单个窗体时的代码
Application->CreateForm(__classid(TForm1), &Form1);
//窗体代码如下
void __fastcall TForm1::FormCreate(TObject *Sender)
{
this->l1 = ListView1->WindowProc;
this->l2 = ListView2->WindowProc;
ListView1->WindowProc = MyProcList1;
ListView2->WindowProc = MyProcList2;
}
//---------------------------------------
void __fastcall TForm1::MyProcList1(TMessage &message)
{
l1(message);
if(message.Msg == WM_VSCROLL || message.Msg == SB_VERT)
{
l2(message);
}
}
void __fastcall TForm1::MyProcList2(TMessage &message)
{
l2(message);
if(message.Msg == WM_VSCROLL || message.Msg == SB_VERT)
{
l1(message);
}
}
Application->CreateForm(__classid(TfrmMain), &frmMain);
Application->CreateForm(__classid(TdlgShowDiff), &dlgShowDiff);
Application->CreateForm(__classid(TdlgMainframeEdit), &dlgMainframeEdit);
Application->CreateForm(__classid(TfrmLevelSet), &frmLevelSet);
Application->CreateForm(__classid(TfrmOptionSet), &frmOptionSet);
Application->CreateForm(__classid(TfrmTermSet), &frmTermSet);
Application->CreateForm(__classid(TfrmAbout), &frmAbout);
Application->CreateForm(__classid(TfrmCompare), &frmCompare);
Application->CreateForm(__classid(TfrmShowPara), &frmShowPara);
Application->CreateForm(__classid(TfrmDataDiff), &frmDataDiff);
//窗体代码如下
//---------------------------------------
void __fastcall TfrmCompare::FormCreate(TObject *Sender)
{
this->l1 = ListView1->WindowProc;
this->l2 = ListView2->WindowProc;
ListView1->WindowProc = MyProcList1;
ListView2->WindowProc = MyProcList2;
}
//---------------------------------------
void __fastcall TfrmCompare::MyProcList1(TMessage &message)
{
l1(message);
if(message.Msg == WM_VSCROLL || message.Msg == SB_VERT)
{
l2(message);
}
}
//---------------------------------------
void __fastcall TfrmCompare::MyProcList2(TMessage &message)
{
l2(message);
if(message.Msg == WM_VSCROLL || message.Msg == SB_VERT)
{
l1(message);
}
}
[C++ Error] srcCompare.cpp(4158): E2034 Cannot convert 'void (* (_closure )(TMessage &))(TMessage &)' to 'void (_fastcall * (_closure )(TMessage &))(TMessage &)'
[C++ Error] srcCompare.cpp(4162): E2356 Type mismatch in redeclaration of 'TfrmCompare::MyProcList1(TMessage &)'
[C++ Error] srcCompare.h(111): E2344 Earlier declaration of 'TfrmCompare::MyProcList1(TMessage &)'
[C++ Error] srcCompare.cpp(4171): E2356 Type mismatch in redeclaration of 'TfrmCompare::MyProcList2(TMessage &)'
[C++ Error] srcCompare.h(112): E2344 Earlier declaration of 'TfrmCompare::MyProcList2(TMessage &)'
[解决办法]
你这个单元够长的啊。
检查一下MyProcList1和MyProcList2的声明,有__fastcall修饰吗?