It doesn't crash for me: Win98 (and IE 6 fully patched), perl 5.8.7, Win32::GUI 1.02

Here's an alternative.  Does this crash for you?

Yes still crashes - on 5.8.7 and 5.6.1 both Win32::GUI 1.02, I'm on XP Sp2...

Win32-GUI in both cases was the binary from sourceforge, not my own build.

Leaving the crashing aside for the moment, a key line in your changes (or rather the comments) was:

-onClick => sub{Search($self)},  # closure
                                # wouldn't it be nice to have
                                # a way to navigate up to parent
                                # objects as well as down to children

Your comments hit the nail on the head. You could argue that the real problem is that there is no way to navigate from the event in the control, to the window which it belongs, to the perl 'thing' that owns the instance data for the window/object. Perhaps something like this would work:

sub #the constructor for the window/object
 my $window= createwindow
 $window->create lots of controls;
#We now add instance data to the window, which we can read and set as we like #it should mean we can get away with closures, and it should be simple enough to deal
 #with when we free the window.
$window->InstanceData({}); #set the instance data for the window as a empty hash

 return window;
}

sub #some event handler for a control
my $self=shift;
my $parentwindow=$self->GetParent;
my $instancedata=$parentwindow->InstanceData;
if ($instancedata->{something}) {
 #do logic here...
}

Here we fetch the parent window (of the control) via the method GetParent (which doesn't actually exist in win32-gui), we then call a new method InstanceData which returns an SV that was squirreled away on object creation.

I do something similar in some of my code already - I add my own data to the window hash - I just had to make sure I didn't clobber anything...A formal approach would be better.

Thoughts?

Cheers,

jez.



Reply via email to