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?

#!perl -w
use strict;
use warnings;

use Win32::GUI;

# Create the main window
my $mainwindow = new Win32::GUI::Window(
   -name   => "Window",
   -title  => "Objects and Windows",
   -pos    => [100,100],
   -size   => [400,400],
);

#We now create several employee selector 'controls'.
my $search1=EmployeeSelector->new($mainwindow,20,20);
my $search2=EmployeeSelector->new($mainwindow,20,50);
my $search3=EmployeeSelector->new($mainwindow,20,80);
my $search4=EmployeeSelector->new($mainwindow,20,110);
my $search5=EmployeeSelector->new($mainwindow,20,140);
#Show all our controls
$search2->Move(200,200);

# Child windows don't show until their parent shows, so by
# showing the main window last we can create the child
# windows with WS_VISIBLE, and not see them drawing
$mainwindow->Show();
#Enter the message processing loop
Win32::GUI::Dialog();
exit(0);

# package to encapsulate the search window.
# one static (class) function that diaplays the
# search window and returns the selected item
# or undef if ESC/Cancel preseed
package SearchWindow;
use strict;
use warnings;
use Win32::GUI;

our $searchwindow;
our $ok;  # there has to be a better way to determine
          # which button was pressed perhaps buttons with -ok/-cancel
          # should exit the DoModal loop, returning some
          # well defined values?

sub DoSearch {

        unless ($searchwindow) {
                # create it first time we're called
                # depending how much this gets called it's questionable
                # whether it's worth keeping it hanging around

                $searchwindow = Win32::GUI::DialogBox->new(
                        -title       => "Search for Employee",
                        -size        => [300,270],
                        -onTerminate => sub { $ok = 0; return -1;},
                );
                $searchwindow->AddListView(
                        -name          => "ListView",
                        -pos           => [8,8],
                        -size          => [280,189],
                        -singlesel     => 1,
                        -fullrowselect => 1,
                        -tabstop       => 1,
                );
                $searchwindow->AddButton (
                        -text    => 'OK',
                        -pos     => [164,208],
                        -size    => [60,21],
                        -tabstop => 1,
                        -default => 1,  # draw button in 'default' style
                        -ok      => 1,  # respond to 'return' key
                        -onClick => sub{ $ok = 1; return -1;},
                );
                $searchwindow->AddButton (
                        -text    => 'Cancel',
                        -pos     => [228,208],
                        -size    => [60,21],
                        -tabstop => 1,
                        -cancel  => 1,  # respond to ESC key
                        -onClick => sub{ $ok = 0; return -1;},
                );

                #populate the list view
                $searchwindow->ListView->InsertColumn(-width => 55,-text  => 
'Emp ID');
$searchwindow->ListView->InsertColumn(-width => 205,-text => 'Employee Name');
                $searchwindow->ListView->InsertItem(-text => [1234, 'Bob 
Smith']);
                $searchwindow->ListView->InsertItem(-text => [4321, 'Peter 
Jones']);
                $searchwindow->ListView->InsertItem(-text => [7890, 'John 
Brown']);

        }

        # show the search window and return the searched out value
        $searchwindow->Center();
        $searchwindow->ListView->SetFocus();
        $searchwindow->DoModal(1);
        
        return undef unless $ok;  # pressed cancel or ESC (or X in titlebar)
  my $item=$searchwindow->ListView->SelectedItems();
return undef unless defined $item; # no selection (undef gets treated as zero by ItemInfo)
        my %hItem=$searchwindow->ListView->ItemInfo($item,0);
  return $hItem{-text};
}

# I don't really understand why this end block is necessary to avoid warnings
END
{
        undef $searchwindow;
}

#package to encapsulate the 'Employee Selector' control
# subclass of Window, so that I don't have to implement
# Move()/Show() etc.
package EmployeeSelector;
use strict;
use warnings;
use Win32::GUI;
use base qw(Win32::GUI::Window);

#The constructor
sub new
{
        my ($class, $parent, $xcor, $ycor)[EMAIL PROTECTED];

        #Create window
        my $self = $class->SUPER::new(
                -parent    => $parent,
                -pos       => [$xcor,$ycor],
                -size      => [150, 24],
                -popstyle  => WS_CAPTION | WS_SIZEBOX,
                -pushstyle => WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,
        );

        #Create other controls
        $self->AddLabel(
                -text   => 'ID#',
                -pos    => [0,6],
                -size   => [20,20],
        );
        $self->AddTextfield(
                -name   => "EMPID",
                -pos   => [20,2],
                -size  => [35,20],
                -tip    => 'Employee ID',
        );
  $self->AddButton (
                -text   => 'Search',
                -pos    => [60,2],
                -size  => [60,20],
                -tip    => 'Search for a Employee  ID',
                -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
        );

        return $self;
}

sub Search
{
        my $self = shift;

        my $result = SearchWindow::DoSearch();
        $self->SetEmpID($result) if $result;

        return 1;
}

sub SetEmpID
{
        my $self=shift;
        $self->EMPID->Text(shift);
}


Jeremy White wrote:
This is a known bug with win32-gui.
It is fixed by using perl 5.7 or later or using the circular ref patch


Ok - I've created a tracker item so this issue isn't lost:)

https://sourceforge.net/tracker/index.php?func=detail&aid=1248578&group_id=16572&atid=116572

I've just ran that example under 5.8.7 and it still crashed?

I posted to the list during the 1.02 release cycle. A similar section was applied some years ago, but removed because older perl don't allow circular refs at all.


I just searched the archive but it doesn't show any attachments - could you forward it again so I can see if it fixes the problem?

Cheers,

jez.




-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Perl-Win32-GUI-Hackers mailing list
Perl-Win32-GUI-Hackers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-hackers


Reply via email to