Hi People,
I just thought I'd post this thought.
I've variously been having problems with pieces of code if I run them
too often (actually, it turned out that this was because I had created
but not activated my swap file. Who'd have guessed?). Anyway in the
course of trying to track this down, I came up with the following piece
of code, which I decided to circulate (maybe you all do it anyway).
First of all I create a global variable called $gl_dialog_base, then if
I want to create a screen, say i_Booking, I use a derived function
i_Booking -> new, which creates the dialog box and paints the controls.
Then I populates the controls with data (setInitialDataState).
I update the global variable and the next time round I just populate the
data.
Like this:
if (not $gl_dialog_base{bookingNew}){
$dlg_booking= i_Booking -> new ($i_frame, wxID_ANY, wxID_ADD,
wxDefaultPosition,[$gl_cfg->{monitor_resolution_x},
$gl_cfg->{monitor_resolution_y}], wxNO_BORDER, "" );
$dlg_booking->setInitialDataState(wxID_ADD);
$gl_dialog_base{bookingNew} = {
instantiated => 1,
dialog_pointer => $dlg_booking,
};
} else {
$dlg_booking= $gl_dialog_base{bookingNew}{dialog_pointer};
$dlg_booking->setInitialDataState(wxID_ADD);
}
It's more efficient, much quicker, uses less memory and crashes less
frequently (if you haven't activated your swap file).
If anyone else has any ideas for efficiency, I'd love to hear.
Have fun,
Regards,
Steve.