How do I pick up existing objects in event handling code?

Discussion in 'Perl Misc' started by Graham Wood, Aug 16, 2004.

  1. Graham Wood

    Graham Wood Guest

    I've written an FTP client using the GUI Loft and Net::FTP. I've
    managed to get the program to work by scoping the $ftp object with "our"
    but I don't think this is how you are supposed to do it.

    Here's an artist's impression of what I'm doing now:

    our $ftp= Net::FTP->new("hostname")|| die "Can't create FTP object";

    sub ::btnChdir_Click{
    our $ftp;
    # get $path from value in a text box
    $ftp->cwd("$path");
    }

    sub ::btnOK_Click{
    our $ftp;
    $ftp->put("$file");
    }

    sub ::btnDisconnect_Click{
    our $ftp;
    $ftp->quit();
    }

    I know that I could pass the $ftp object as an argument to subroutines
    if I were calling them from my script but in this event driven model,
    how do I elegantly pick up the value of the existing ftp object without
    letting it all hang out in this unseemly fashion?

    I notice that the gui $win object is picked up with code like this:

    defined(my $win = $Win32::GUI::Loft::window(winCopyFiles})
    or return (1);

    Can I do something similar with Net::FTP objects like
    defined(my $ftp = $Net::FTP);

    Any hints gratefully accepted.

    Thanks

    Graham
     
    Graham Wood, Aug 16, 2004
    #1
    1. Advertising

  2. Graham Wood <> wrote in message news:<8S2Uc.30$>...
    > I notice that the gui $win object is picked up with code like this:
    >
    > defined(my $win = $Win32::GUI::Loft::window(winCopyFiles})
    > or return (1);
    >
    > Can I do something similar with Net::FTP objects like
    > defined(my $ftp = $Net::FTP);


    Yes, you can attach an object to the Win32::GUI::Loft::Design object
    you created when loading the design from the .gld file. The property
    is called objApp:

    Some user-defined object, normally used to connect a
    application object responsible for this window.

    So if you assign your FTP object (or any object) to the Design like
    this (untested code):

    my $objDesign = Win32::GUI::Loft::Design->newLoad($fileWindow); #or
    die
    $objDesign->objApp($ftp);

    then you can get it out of the object in the event handlers like this:

    my ($win, $design, $ftp) = tglApp('yourWindowName) or die;

    Something like that.


    I happened to stumble across this post by accident. There is a support
    mailing list at the TGL site which I at least read a bit more often:
    http://www.bahnhof.se/~johanl/perl/Loft/


    /J
     
    Johan Lindstrom, Aug 18, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nrm
    Replies:
    3
    Views:
    541
  2. tom c
    Replies:
    5
    Views:
    405
    tom c
    Nov 1, 2006
  3. Replies:
    0
    Views:
    193
  4. ThomasW
    Replies:
    11
    Views:
    288
    ThomasW
    Sep 28, 2009
  5. Replies:
    7
    Views:
    242
    Arne Vajhøj
    Aug 4, 2012
Loading...

Share This Page