From: Fibre Optic on
Eric Jensen wrote:
>>> No, it's not ok. The 'this' pointer in the OnSelected method will be a
>>> pointer to the MyListCtrl instance. The MyFrame::OnSelectedT method
>>> itself will of course "think" that 'this' points to a MyFrame instance.
>>> That's causing the crash.
>>>
>>> You have 2 options:
>>> a) make the method static (so that you can't use 'this'), and rewrite
>>> it (use Event::GetEventObject() to get the MyListCtrl object, from
>>> there you can use GetParent() to get the MyFrame and so on)
>>>
>>> b) instead of the event table macro, use MyListCtrl->Connect() and set
>>> the eventsink parameter to MyFrame.
>
> FO> b)
>
> FO> MyListCtrl is my class definition. Do you mean 'navigation' which is
> FO> object of the MyListCtrl class? If yes, wow should look the
> navigation->>Connect line?
>
>
> navigation->>Connect(LIST_CTRL, EVT_LIST_ITEM_SELECTED,
> FO> wxCommandEventHandler(MyFrame::OnSelectedT));
>
> FO> EVT_LIST_ITEM_SELECTED does not work with dynamic event routing, what i
> FO> shoul use in this context ?
>
> assuming that this code runs in a MyFrame context (this=Myframe *)
> navigation->Connect(id, wxEVT_COMMAND_LIST_ITEM_SELECTED, wxCommandEventHandler(MyFrame::OnSelectedT), NULL, this);
>

the line is as follows:

navigation->Connect(LIST_CTRL, wxEVT_COMMAND_LIST_ITEM_SELECTED,
wxCommandEventHandler(MyFrame::OnSelectedT), NULL, this);

unfortunately during linking process i see the following message:

MyFrame.o: In function `ZNK12wxWindowBase13GetClientSizeEv':
E:/Msys/1.0/wxWidgets-static/include/wx-2.7/wx/gdicmn.h:(.text$_ZN10MyListCtrlC1EP8wxWindowiRK7wxPointRK6wxSizel[MyListCtrl::MyListCtrl(wxWindow*,
int, wxPoint const&, wxSize const&, long)]+0xd1): undefined reference to
`vtable for MyListCtrl'
collect2: ld returned 1 exit status

mingw32-make.exe: *** [wxDivingLogBook.exe] Error 1

Execution terminated
From: Fibre Optic on
Fibre Optic wrote:

> unfortunately during linking process i see the following message:
>
> MyFrame.o: In function `ZNK12wxWindowBase13GetClientSizeEv':
> E:/Msys/1.0/wxWidgets-static/include/wx-2.7/wx/gdicmn.h:(.text$_ZN10MyListCtrlC1EP8wxWindowiRK7wxPointRK6wxSizel[MyListCtrl::MyListCtrl(wxWindow*,
> int, wxPoint const&, wxSize const&, long)]+0xd1): undefined reference to
> `vtable for MyListCtrl'
> collect2: ld returned 1 exit status
>
> mingw32-make.exe: *** [wxDivingLogBook.exe] Error 1
>
> Execution terminated

FIXED!!!

In definition of MyListCtrl I had the following line:

DECLARE_EVENT_TABLE()

After commenting out the code compiles/links without problem. Moreover
it works!!!

I did not change anything except commenting out above mentioned line and

switching from static -> dynamic event route. Now there is no problem
with value of navigation pointer... To be honest with you, it was try
and check method, I am not sure how it works. Do you have detailed
explanation? I have a book about wxWidgets (by dr Julian S.) but I do
not recollect anything about similar problems...

I have one question (i hope it is not to general): is it reasonable to
switch from static -> dynamic routing events generally?

PS

I wanted to say thank you to all of you!!!

Best Regards,
Fibre Optic