我發佈了 "How to undersand the POE-Tk use of destroy?",試圖將我的生產代碼中的錯誤減少到測試用例。但是似乎測試用例的解決方案在整個程序中不起作用。瞭解POE-Tk中的名稱空間
該程序長度超過800行,所以我很猶豫是否要將其完整發布。我意識到我在這裏提供的代碼片段可能太短而沒有任何用處,但我希望能夠在尋找解決方案的地方或我可以提供哪些附加信息方面獲得指導。
這是我的POE-Tk應用的Session :: Create部分。
POE::Session->create(
inline_states => {
_start => \&ui_start,
get_zone => \&get_zone,
ping => \&ping,
mk_disable => \&mk_disable,
mk_active => \&mk_active,
pop_up_add => \&pop_up_add,
add_button_press => sub {
my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP];
print "\nadd button pressed\n\n";
&validate;
},
ih_button_1_press => sub {
my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP];
print "\nih_button_1 pressed\n\n";
if(Tk::Exists($heap->{ih_mw})) {
print "\n\nih_mw exists in ih_button_1_press\n\n";
} else {
print "\n\nih_mw does not exist in ih_button_1_press\n\n";
}
1;
$heap->{ih_mw}->destroy if Tk::Exists($heap->{ih_mw});
&auth;
},
pop_up_del => \&pop_up_del,
auth => \&auth,
# validate => \&validate,
auth_routine => \&auth_routine,
raise_widget => \&raise_widget,
del_action => \&del_action,
over => sub { exit; }
}
);
add_button_press
在這裏被稱爲;
sub pop_up_add {
...
my $add_but_2 = $add_frm_2->Button(
-text => "Add Record",
-command => $session->postback("add_button_press"),
-font => "{Arial} 12 {bold}") -> pack(
-anchor => 'c',
-pady => 6,
);
...
}
validate創建Toplevel小部件$ heap - > {ih_mw};
sub validate {
...
if(! $valid) {
print "\n! valid entered\n\n";
$heap->{label_text} .= "Add record anyway?";
my $lt_ref = \$heap->{label_text};
...
my $heap->{ih_mw} = $heap->{add_mw}->Toplevel(-title => "ih_mw");
...
if(Tk::Exists($heap->{ih_mw})) {
print "\n\nih_mw exists in validate\n\n";
} else {
print "\n\nih_mw does not exist in validate\n\n";
}
...
my $ih_but1 = $heap->{ih_mw}->Button(-text => "Add",
-font => 'vfont',
-command => $session->postback("ih_button_1_press"),
)->pack(-pady => 5);
...
}
按$ ih_but1結果在此;
C:\scripts\alias\resource>alias_poe_V-3_0_par.pl
添加按鈕按下
稱爲
子驗證!有效進入
ih_mw
存在於驗證
ih_button_1
按下
ih_mw
在ih_button_1_press
不存在這樣的$heap->{ih_mw}
部件似乎是未知的ih_button_1_press
匿名子即使列入「($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP];
「
請嘗試查看$ heap和$ heap - > {ih_mw)是否都被實際定義()。如果沒有定義$ heap,那麼你可能仍然會遇到與上一篇文章相同的問題。 – Inshallah 2009-07-20 20:22:28
我在if(Tk :: Exists($ heap - > {ih_mw}))前加了一個if(defined($ heap))。它回來了,$堆被定義。 ih_button_1壓... 堆被定義... ih_mw不存在ih_button_1_press ... – jpolache 2009-07-20 20:29:42