Hi Mattia, Thank you for this solution. It works. However, I just found a bug in another program I made that was caused by re-blessing an object and I am afraid that this re-blessing might cause problems in the future and I might need to redesign the app.
It would be very helpful if you could change the constructors, because it is the same with Wx::Frame, Wx::SimpleApp and others and it is counterintuitive to do use Wx; my $app = Wx::SimpleApp->new; It would be much better if we could do: use Wx::SimpleApp; my $app = Wx::SimpleApp->new; This way it would be easier to subclass. Ideally, it would be better to be able to use the constructor of Wx, like: use Wx; my $app = Wx->new; Octavian ----- Original Message ----- From: "Mattia Barbon" <mattia.bar...@libero.it> To: "Octavian Rasnita" <orasn...@gmail.com> Cc: <wxperl-users@perl.org> Sent: Saturday, August 07, 2010 11:47 PM Subject: Re: Subclassing an empty class? > Octavian Rasnita wrote: > > Hi, > >> Is it possible to subclass some empty classes like Wx::TextAttr? > > Some classes are tricky to subclass, but not because they are empty. > >> I have also tried to use Wx: >> >> package Style; >> use Wx; >> use base 'Wx::TextAttr'; >> >> In this case it doesn't tell that Wx::TextAttr is empty, but if I add a >> certain method in this package, that method can't be used because it gives >> the error telling that there is no such a method defined in Wx::TextAttr. > > I'm not sure if this is easy to fix in wxPerl without requiring a > change to all constructors. I'll think about it. In the meantime you > can just rebless the object: > > package Style; > use Wx; > use base 'Wx::TextAttr'; > > sub new { > my $class = shift; > my $self = $class->SUPER::new( @_ ); > bless $self, $class; > > return $self; > } > > 1; > > Note: I haven't tested it, but it should work. One problem with this > approach is that, since the text attr is used as a value in wxWidgets, > there is no way to preserve identity, so if you do: > > $text->SetStyle( 0, 100, $myclass ); > my( $ok, $style ) = $text->GetStyle( 0, 100 ); > > the returned $style object will be a copy of your object, and there is > no way to automatically bless it to the correct class. > > HTH, > Mattia