Leif Andersson wrote:
I had the, maybe bad, idea of putting up a kind of "framework", so I
could manage my windows definitions in external separate files.
Doesn't sound like a bad idea, so far.
In its simplest form it works as expected:
<code>
#!/usr/bin/perl -w
use strict;
use Win32::GUI qw(WS_SYSMENU);
my $handle = do 'mainw.gui' ;
$handle->Show;
Win32::GUI::Dialog();
</code>
But I also wanted to build this around some objects.
So I added a package returning an object.
Now it still appeared to work, but on exit I get some error messages
like:
(in cleanup) Can't call method "DELETE" on an undefined value ...
packages are definitely the right way to go. That particular error
looks like one that has been around since before I took over looking
after the Win32::GUI package. I know where it happens, and have a very
good idea what causes it, but it's in an area of code that I'm not happy
to play with, as I can't find a short script that reliably tickles the
problem.
I beleive that the problem arises due to perl sometimes performing its
final garbage collection sweep in a different order to other times, and
the order seems to change dependent on memory layout - so just changing
a few bytes of the script is sometimes enough to make it go away.
I posted a number of work-arounds to this list a few weeks(months?) ago
- search the archives for that error message.
First, I can't understand what the undefined value is.
(But it clearly has to do with the exported constants.)
I would be very surprised if it had anything to do with exported
constants - much more likely that the changes you make to your script
tickle the memory allocation. (As an aside the code you posted generates
the following error for me 'Can't call method "Show" on an undefined
value at main.pl line 28.' - I have not investigated further)
Second - can I just disregard this message? Should I do it in some other
way? Or should I drop the whole idea?
You can safely ignore the message.
Regards,
Rob.
The version I am using is ActiveState Perl 5.8.8 build 819
with Win32::GUI version 1.0304
Some code to show the error:
#!/usr/bin/perl -w
package NC::GUI;
use strict;
use Carp;
#use Win32::GUI();
# uncomment line above and
# out-comment the line below to make error disappear
use Win32::GUI qw(WS_SYSMENU); # any constant will do
sub new {
my $class = shift;
$class = ref($class) || $class;
my $self = {};
bless $self, $class;
return $self;
}
sub read_form {
my ($self, $filename) = @_;
# read a file containing definitions for a window
$self->{form}->{$filename}->{window} = do $filename ;
}
sub run {
my ($self, $name) = @_;
$self->{form}->{'mainw.gui'}->{window}->Show;
Win32::GUI::Dialog();
}
1;
#-----------------------------------------------------------------------
--
package main;
use strict;
my $obj = new NC::GUI;
$obj->read_form('mainw.gui');
$obj->run();
__END__
#-- And the external file mainw.gui contains:
$mainW = new GUI::DialogBox(
-name => "mainWindow",
-title => "Our main window",
-left => 100,
-top => 100,
-width => 130,
-height => 230,
);
$mainW->AddButton(
-name => "mainButton1",
-text => "Dummy",
-valign => "center",
-left => 70,
-top => 164,
-width => 40,
);
# return handle
$mainW;
#--- end of mainw.gui ---
Thanks for any insights,
Leif
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
http://perl-win32-gui.sourceforge.net/