From: "Robert May" <[EMAIL PROTECTED]>
> Octavian Rasnita wrote:
> > I have tried to set an event handler -onLostFocus, but if the control
loses
> > the focus when the application closes (alt+F4), it gives the following
> > error:
> >
> > Can't call method "Text" on an undefined value at
E:\lucru\agenda\agenda.pl
> > line 68 during global destruction.
> >
> > How can I detect if the control loses the focus because I have pressed
the
> > tab key, or that if the whole application was closed?
>
> I you can post a short and complete example that I can run and see what
> you're doing then I'll have a look to see if you're doing something
> wrong, or whether we have a bug.  You have not posted enough information
> for me to see what you're trying to do.
>

Ok, here is a simple test program.


use strict;
use Win32::GUI;

my $Win = new Win32::GUI::Window(
-title => 'Test',
-pos => [100, 100],
-size => [400, 400],
-dialogui => 1,
);

$Win->AddButton(
-name => 'But',
-text => "&Ok",
-pos => [10, 10],
-size => [100, 20],
-tabstop => 1,
);

my $Field = $Win->AddTextfield(
-name => 'Field',
-pos => [10, 50],
-size => [100, 20],
-tabstop => 1,
);

$Win->Show();
Win32::GUI::Dialog();

sub Win_Terminate {-1}

sub Field_LostFocus {
$Win->But->Text("New text");
}

__END__

The program works fine, and if I press the tab key when the focus is on the
textfield, the focus moves to the button and the text of the button is
changed.
If I close the application in that moment, it closes without errors. But if
I press agan the tab key and the focus moves again to the text field, and
only after this I close the application, it gives an error, because the
onLostFocus event is fired when the application closes.

I have seen that if I give a name to the textfield using:

my $Field = $Win->Textfield(...

and then I use

$Field->Text("...");

instead of

$Win->But->Text("New text");

the program doesn't give an error. But why does it give an error when using
$Win->Field->Text(...)?

Thank you.




Reply via email to