Hello together,
I have written a class who is sending an event.
If I fire the event one time it works everything fine.
But if I fire the event 2 times my application crashes.
Can any body give me a helping hand?
Part of my source:
void csDatabase::CallEvent(){
csDatabase db;
db.SetId(0);
MyEvtHandler *met;
met->ProcessEvent(db);
//met->ProcessThreadEvent(db);
//met->AddPendingEvent(db);
//met->ProcessPendingEvents();
CallEvent2();
}
void csDatabase::CallEvent2(){
csDatabase db;
db.SetId(1);
MyEvtHandler *met;
met->ProcessEvent(db);
}
Have a big thank
kea_
On fire event the application chrashes Topic is solved
Re: On fire event the application chrashes
Is this the actual code you are using, ie... did you cut and paste it? Or did you rewrite a portion of it for the post? I ask because there is a big error for sure and if this is cut and pasted code it will never work as expected.
or with new
-Max
Neither of these are correct c++. met is an uninitialized pointer and you can not ever call a method of it, as it is not actually pointing to an instance of MyEvtHandler. you have to call new first, or better if it is in a functions scope you could just make it an object.kea_ wrote:Code: Select all
// ...snip... MyEvtHandler *met; met->ProcessEvent(db); // ...snip... MyEvtHandler *met; met->ProcessEvent(db); }
Code: Select all
MyEvtHandler met(...Whatever arguments the constructor needs...);
met.ProcessEvent(db);
Code: Select all
MyEvtHandler *met = NULL;
met = new MyEvtHandler(...Whatever arguments the constructor needs...);
if(met){
met->ProcessEvent(db);
// Other stuff with met
delete met;
}
Hello Max,
thank you for your answer.
I show you the complete code.
In the way I do it it works but just for one time.
I tryed it in your way but then it wouldn't work.
Did I do something wrong in the base?
Database.h
#ifndef __csDatabase_h__
#define __csDatabase_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 wxEvent
{
public:
// F U N C T I O N S
csDatabase();
csDatabase(const csDatabase &event);
wxEvent *Clone() const;
void CallEvent();
void CallEvent2();
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
};
class MyEvtHandler : public wxEvtHandler
{
public:
MyEvtHandler();
~MyEvtHandler();
};
BEGIN_DECLARE_EVENT_TYPES()
DECLARE_EVENT_TYPE(myEVT_SAVING, -1)
END_DECLARE_EVENT_TYPES()
typedef void (wxEvtHandler::*csDatabaseFunction)(csDatabase&);
#define EVT_SAVING(fn) \
DECLARE_EVENT_TABLE_ENTRY(myEVT_SAVING, -1, -1, \
(wxObjectEventFunction) (wxEventFunction) \
wxStaticCastEvent(wxCommandEventFunction, & fn), (wxObject *) NULL),
/*
#define EVT_SAVING(fn) \
DECLARE_EVENT_TABLE_ENTRY(myEVT_SAVING, -1, -1, \
(wxObjectEventFunction) (wxEventFunction) \
wxStaticCastEvent(wxCommandEventFunction, & fn), (wxObject *) NULL ),
*/
#endif
csDatabase.cpp
#include "csDatabase.h"
DEFINE_EVENT_TYPE(myEVT_SAVING)
csDatabase::csDatabase()
:wxEvent(){
SetEventType(myEVT_SAVING);
}
csDatabase::csDatabase(const csDatabase &event)
:wxEvent(event){
}
wxEvent *csDatabase::Clone() const{
return new csDatabase(*this);
}
void csDatabase::CallEvent(){
csDatabase db;
db.SetId(0);
MyEvtHandler *met;
met->ProcessEvent(db);
//met->ProcessEvent(db);
//met->ProcessThreadEvent(db);
//met->AddPendingEvent(db);
//met->ProcessPendingEvents();
//CallEvent2();
}
void csDatabase::CallEvent2(){
csDatabase db;
db.SetId(1);
MyEvtHandler *met;
met->ProcessEvent(db);
// met->AddPendingEvent(db);
}
MyEvtHandler::MyEvtHandler()
:wxEvtHandler(){
}
MyEvtHandler::~MyEvtHandler(){
}
Greetings and thanks
kea_
thank you for your answer.
I show you the complete code.
In the way I do it it works but just for one time.
I tryed it in your way but then it wouldn't work.
Did I do something wrong in the base?
Database.h
#ifndef __csDatabase_h__
#define __csDatabase_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 wxEvent
{
public:
// F U N C T I O N S
csDatabase();
csDatabase(const csDatabase &event);
wxEvent *Clone() const;
void CallEvent();
void CallEvent2();
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
};
class MyEvtHandler : public wxEvtHandler
{
public:
MyEvtHandler();
~MyEvtHandler();
};
BEGIN_DECLARE_EVENT_TYPES()
DECLARE_EVENT_TYPE(myEVT_SAVING, -1)
END_DECLARE_EVENT_TYPES()
typedef void (wxEvtHandler::*csDatabaseFunction)(csDatabase&);
#define EVT_SAVING(fn) \
DECLARE_EVENT_TABLE_ENTRY(myEVT_SAVING, -1, -1, \
(wxObjectEventFunction) (wxEventFunction) \
wxStaticCastEvent(wxCommandEventFunction, & fn), (wxObject *) NULL),
/*
#define EVT_SAVING(fn) \
DECLARE_EVENT_TABLE_ENTRY(myEVT_SAVING, -1, -1, \
(wxObjectEventFunction) (wxEventFunction) \
wxStaticCastEvent(wxCommandEventFunction, & fn), (wxObject *) NULL ),
*/
#endif
csDatabase.cpp
#include "csDatabase.h"
DEFINE_EVENT_TYPE(myEVT_SAVING)
csDatabase::csDatabase()
:wxEvent(){
SetEventType(myEVT_SAVING);
}
csDatabase::csDatabase(const csDatabase &event)
:wxEvent(event){
}
wxEvent *csDatabase::Clone() const{
return new csDatabase(*this);
}
void csDatabase::CallEvent(){
csDatabase db;
db.SetId(0);
MyEvtHandler *met;
met->ProcessEvent(db);
//met->ProcessEvent(db);
//met->ProcessThreadEvent(db);
//met->AddPendingEvent(db);
//met->ProcessPendingEvents();
//CallEvent2();
}
void csDatabase::CallEvent2(){
csDatabase db;
db.SetId(1);
MyEvtHandler *met;
met->ProcessEvent(db);
// met->AddPendingEvent(db);
}
MyEvtHandler::MyEvtHandler()
:wxEvtHandler(){
}
MyEvtHandler::~MyEvtHandler(){
}
Greetings and thanks
kea_
Hello to all,
I solved the problem.
Just pointed to the MyEvtHandler once an called the function ProcessEvent more times.
See the code below.
void csDatabase::CallEvent(){
csDatabase db;
db.SetId(0);
MyEvtHandler *met;
met->ProcessEvent(db);
CallEvent2(db, met);
}
void csDatabase::CallEvent2(csDatabase &i_db, MyEvtHandler *i_met){
i_db.SetId(1);
i_met->ProcessEvent(i_db);
}
I solved the problem.
Just pointed to the MyEvtHandler once an called the function ProcessEvent more times.
See the code below.
void csDatabase::CallEvent(){
csDatabase db;
db.SetId(0);
MyEvtHandler *met;
met->ProcessEvent(db);
CallEvent2(db, met);
}
void csDatabase::CallEvent2(csDatabase &i_db, MyEvtHandler *i_met){
i_db.SetId(1);
i_met->ProcessEvent(i_db);
}