验证wxPerl中的文本框值会导致perl解释器崩溃

时间:2013-12-19 21:21:28

标签: perl wxwidgets wxperl

我正在使用:

  • Windows 7
  • Strawberry Perl
  • 使用当前版本的wxPerl(来自CPAN)

创建布局的perl代码由wxGlade生成。 此代码导致错误“Perl Interpretor已停止工作”:

use Wx 0.15 qw[:allclasses];
use strict;

# begin wxGlade: dependencies
# end wxGlade

# begin wxGlade: extracode
# end wxGlade


package MyFrame;

use Wx;
use Wx qw[:everything];
use Wx::Event qw( EVT_BUTTON EVT_CLOSE );
use Wx::Perl::TextValidator;
use base qw(Wx::Frame Class::Accessor::Fast);
use strict;

use Wx::Locale gettext => '_T';

__PACKAGE__->mk_ro_accessors( qw(numeric string) );

sub new {
my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_;
$parent = undef              unless defined $parent;
$id     = -1                 unless defined $id;
$title  = ""                 unless defined $title;
$pos    = wxDefaultPosition  unless defined $pos;
$size   = wxDefaultSize      unless defined $size;
$name   = ""                 unless defined $name;

# begin wxGlade: MyFrame::new
$style = wxDEFAULT_FRAME_STYLE 
    unless defined $style;
my $numval = Wx::Perl::TextValidator->new( '\d' );

$self = $self->SUPER::new( $parent, $id, $title, $pos, $size, $style, $name );
$self->{text_ctrl_1} = Wx::TextCtrl->new($self, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, );
$self->{button_1} = Wx::Button->new($self, wxID_ANY, _T("Get"));
$self->{label_1} = Wx::StaticText->new($self, wxID_ANY, _T("From:"), wxDefaultPosition, wxDefaultSize, );
$self->{text_ctrl_2} = $self->{numeric} = Wx::TextCtrl->new($self, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, );
$self->{label_2} = Wx::StaticText->new($self, wxID_ANY, _T("To:    "), wxDefaultPosition, wxDefaultSize, );
$self->{text_ctrl_3} = $self->{numeric} = Wx::TextCtrl->new($self, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, );
$self->{radio_box_1} = Wx::RadioBox->new($self, wxID_ANY, _T("Vote?"), wxDefaultPosition, wxDefaultSize, [_T("Yes"), _T("No")], 2, wxRA_SPECIFY_ROWS);
$self->{text_ctrl_4} = Wx::TextCtrl->new($self, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);

$self->__set_properties();
$self->__do_layout();

# end wxGlade

$self->{text_ctrl_2}->SetValidator ( $numval ); #<- this is where the program crashes
$self->{text_ctrl_3}->SetValidator ( $numval ); #<- this WORKS actually

EVT_BUTTON(
    $self,
    $self->{button_1},
    \&GetURL
    );

EVT_CLOSE(
    $self,
    \&OnClose
    );

return $self;
}

在对这两个textctrl进行数字验证之前,我没有错误。我要做的是只接受我的字段中的数字。

我正在使用wxperl_demo作为我的文档。

第二个SetValidator工作的事实对我很好奇,可能是什么问题?

1 个答案:

答案 0 :(得分:1)

显然,您不能将相同的变量用作SetValidator的参数两次。用另一个解决了这个问题。