I'm not quite understanding what you are asking here Pete.  Are you simply
saying that you want the "$Bad_Results" window to appear every time you
click "Button_1"?

If so, then create the "$Bad_Results" window inside of the "Button_1_Click"
subroutine.  If you place "my $Bad_Results;" outside of that subroutine,
then the window object will be available to other subroutines, after it has
been created.

When you create the window outside of the subroutine, display it, and then
close it, you've just destroyed the window (by calling the default
_Terminate subroutine).  Once the object is destroyed, you obviously can't
call it's methods anymore which is why "$Bad_Results->Show();" stopped
working.

I may be way off in what you are asking here, so correct me if I'm wrong.

jb
----- Original Message -----
From: "Pete" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; <perl-win32-gui-users@lists.sourceforge.net>
Sent: Sunday, January 20, 2002 9:56 AM
Subject: [perl-win32-gui-users] perl-win32-gui-users win32:gui in a
subroutine


> I'm trying to get a routine running as either a subroutine or more ideally
> an object(using strict and diagnostic). It works fine if it  is all in the
> main body but once I put it in  a subroutine It generates errors when
trying
> to access the subroutine called from the "button Click" subroutine. So far
I
> can't see any way round this. I have include an extract below. Thanks in
> advance.
>
> my $Win = new Win32::GUI::Window(
>        -left   => 276,
>        -top    => 365,
>        -width  => 580,
>        -height => 361,
>        -name   => "Win",
>        -text   => "Single Runner"
>        );
>
>  my $Bad_Results = new Win32::GUI::Window(
>        -left   => 460,
>        -top    => 372,
>        -width  => 300,
>        -height => 300,
>        -name   => "Results",
>        -text   => "Results"
>        );
>
>  $Win->AddButton(
>         -text    => "Push Me!!",
>         -name    => "Button_1",
>         -left    => 200,
>         -top     => $Row,
>         -width   => 150,
>         -height  => 23,
>         -foreground    => 0,
>        );
>
>   sub Button_1_Click
>   { $Bad_Results->Show();}
>
> The eror message is of the following
>
> Variable "$Bad_Results" will not stay shared at rts_gui.pm line 435 (#1)
>     (W closure) An inner (nested) named subroutine is referencing a
>     lexical variable defined in an outer subroutine.
>
>     When the inner subroutine is called, it will probably see the value of
>     the outer subroutine's variable as it was before and during the
*first*
>     call to the outer subroutine; in this case, after the first call to
the
>     outer subroutine is complete, the inner and outer subroutines will no
>     longer share a common value for the variable.  In other words, the
>     variable will no longer be shared.
>
>     Furthermore, if the outer subroutine is anonymous and references a
>     lexical variable outside itself, then the outer and inner subroutines
>     will never share the given variable.
>
>     This problem can usually be solved by making the inner subroutine
>     anonymous, using the sub {} syntax.  When inner anonymous subs that
>     reference variables in outer subroutines are called or referenced,
they
>     are automatically rebound to the current values of such variables.
>
>
> _______________________________________________
> Perl-Win32-GUI-Users mailing list
> Perl-Win32-GUI-Users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
>
>
> _______________________________________________
> Perl-Win32-GUI-Users mailing list
> Perl-Win32-GUI-Users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


Reply via email to