Code: Select all
buttonGrid = new wxButton * [nFieldWidth * nFieldHeight];
wxGridSizer* grid = new wxGridSizer(nFieldWidth, nFieldHeight, 0, 0);
// for the specified number of buttons, loop thru and build grid of buttons
for (int x = 0; x < nFieldWidth; x++) {
for (int y = 0; y < nFieldHeight; y++) {
buttonGrid[y * nFieldWidth + x] = new wxButton(panel_center, 10010 + (y * nFieldWidth + x));
grid->Add(buttonGrid[y*nFieldWidth + x], 1, wxEXPAND | wxALL);
//dynamically bind buttons to event handler
buttonGrid[y*nFieldWidth + 1]->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &cppMain::OnGridClick, this);
}
}
//tell parent which sizer to use
panel_center->SetSizerAndFit(grid);
//adjust layout with new given information
grid->Layout();
From the error message I can see that "this" is not initialized (due to the read value being 0xCDCDCDCD); But I am honestly a little unsure of what "this" is referencingException thrown: read access violation.
this was 0xCDCDCDCD.
i thought that it was referring to the button that originally generated this event, but since i have that initialized in my header file as
Code: Select all
int nFieldWidth = 10;
int nFieldHeight = 5;
wxButton** buttonGrid = nullptr; //array of button pointers
I have referred to https://docs.wxwidgets.org/trunk/overvi ... vents_bind for help and read that:
which gives me hope for this method of dynamic event binding, but i just think i'm a little tied up with/confused on what needs to be used as the argument for what my frame handler should be..MyFrame::MyFrame(...)
{
m_child->Bind(wxEVT_LEAVE_WINDOW, &MyFrame::OnMouseLeave, this);
}
will work exactly as expected. Note that you can get the object that generated the event – and that is not the same as the frame – via wxEvent::GetEventObject() method of event argument passed to the event handler.
{all help is appreciated, pls & thank you}