I try to program my own class with an event in it.
But unfortunately I get the error: invalid static_cast from type 'void(fmFrame::*)(wxCommandEvent&)' to type 'void(wxEvtHandler::*)(csDatabase&)'
I do not know what's wrong. Can any body give me a helping hand?
I'm using the wxDev-C++
her is the source:
csDatabase.h
Code: Select all
#ifndef csDatabase_h
#define csDatabase_h
#include "csConfig.h"
#include <wx/event.h>
// For compilers that support precompilation, includes "wx.h".
#include <wx/wxprec.h>
#ifdef __BORLANDC__
#pragma hdrstop
#endif
class csDatabase : public wxNotifyEvent
{
public:
// F U N C T I O N S
csDatabase(wxEventType commandType = wxEVT_NULL, int id = 0);
csDatabase(const csDatabase &event);
wxEvent *Clone();
void CallEvent();
DECLARE_DYNAMIC_CLASS(csDatabase);
private:
// P A R A M E T E R S
// F U N C T I O N S
// E V E N T S
// E N U M
};
BEGIN_DECLARE_EVENT_TYPES()
DECLARE_EVENT_TYPE(myEVT_SAVING, -1)
END_DECLARE_EVENT_TYPES()
typedef void (wxEvtHandler::*csDatabaseFunction)(csDatabase&);
#define EVT_SAVING(id, fn) \
DECLARE_EVENT_TABLE_ENTRY( \
myEVT_SAVING, id, wxID_ANY, \
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent(csDatabaseFunction, &fn ), (wxObject *) NULL ),
#endif
Code: Select all
#include "csDatabase.h"
//IMPLEMENT_DYNAMIC_CLASS(csDatabase, wxEvent)
DEFINE_EVENT_TYPE(myEVT_SAVING)
csDatabase::csDatabase(wxEventType commandType, int id)
:wxNotifyEvent(commandType, id){
}
csDatabase::csDatabase(const csDatabase &event)
:wxNotifyEvent(event){
}
wxEvent *csDatabase::Clone(){
return new csDatabase(*this);
}
void csDatabase::CallEvent(){
for(int i = 0; i < 10; i++){
if(i = 5){
csDatabase event(myEVT_SAVING, GetId());
event.SetEventObject(this);
event.ProcessEvent(event);
GetEventHandler()->ProcessEvent(event);
}
}
}
Code: Select all
BEGIN_EVENT_TABLE(fmFrame, wxFrame)
EVT_BUTTON(ID_BUTTON1, fmFrame::OnButton)
EVT_BUTTON(ID_BUTTON2, fmFrame::OnButton)
EVT_SAVING(-1, fmFrame::OnSaving)
END_EVENT_TABLE()
void fmFrame::OnSaving(wxCommandEvent &event){
// do something
}
kea_