From: John R. <jr...@ce...> - 2006-07-25 15:49:01
|
On Jul 25, 2006, at 12:16 AM, Mark Wardell wrote: > Hello, > > Further investigation has revealed that $this->FindWindow( $name ) > returns a > HASH ref for all other controls I have tested but ONLY returns a > SCALAR ref > for controls of type Wx::Grid. > > I use this _BAD_ method of reblessing as a way of initialising > subclassed > controls (as below) that I am loading from XRC and have no other > way of > initialising them. SubclassFactory provides a way to override the > default > ->new() method (with no parameters), but there is no other way to > override a > Create or Show to provide any further customisation. So I am forced to > manually Init each control in my OnInitDialog handler. > > if (my $grid = $self->FindWindow('DiscountGrid')) { > bless $grid, 'Grid::DiscountGrid'; > print "Grid::DiscountGrid => $grid\n"; > $grid->InitControl( $self ); > } > > I suppose I could prevent the reblessing by simply declaring the > subclassing > in the XRC definition but I would still have the problem of FindWindow > returned a SCALAR instead of a HASH and I need the HASH as I use a > lot of > code like below: > > $self->{Option1} = $var; > > Can anyone offer any pointers where I can start looking or possible > alternative solutions. > > Thanks in advance. > > Mark Yeah, http://wxperl.pvoice.org/kwiki/index.cgi?SubclassingXRC. Perl's OO works, but it's a hack, and a bit fragile because it doesn't enforce anything (which is why you can rebless in the first place, but also why it will produce interesting results sometimes). If you declare your subclass the documented way (either with use base or by putting the superclass in the @ISA) then call SUPER::new in your own new (or don't write a new at all) then your subclass object will be correctly blessed. Regards, John Ralls |