Results 1 to 9 of 9

Thread: RaiseEvent and Classes (need expert's help)

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    7

    RaiseEvent and Classes (need expert's help)

    Ok, so here i am all happy n stuff, working on a FTP Server in VB.NET.
    Feel like I'm in paradise cause I recently switched over from VB6.

    Heres the problem.

    I have the following Classes

    ServerClass
    > which contains ListenerClass (private)
    > which in turn contains ClientClass (private)

    so its like ServerClass.ListenerClass.ClientClass

    The server class contains a event, "InternalMessage"
    ie. Public Shared Event InternalMessage(ByVal theMsg as String)

    (don't worry i shall provide sample code...read on plz )

    Now basically I'm developing a windows service, but I'm doing the actual developing as a console application to make everything easy.
    so this console application basically creates the "server class"
    and simply calls a serverclass.start to start up the whole FTP Server.
    However I want the serverclass and its internal classes to be able to report back to the "Mother Application" which can be either a console application or whatever.
    SOOOO, BASICALLY whan a remote host connects I want the ClientClass to be able to pass on a message to the Mother Application via what'ever means nessesary.
    Heres the sample code.

    Module Module1
    dim withevents ftp as new serverclass

    sub Main()
    ftp.startservice
    console.readline()
    end sub

    sub onMessage(ByVal theMessage as String) Handles ftp.InternalMessage
    console.writeline(theMessage)
    end sub
    end Module

    that was the mother application
    these are the classes

    public class ServerClass
    Public Shared Event InternalMessage(ByVal msg as string)

    public sub StartService()
    raiseevent internalmessage("Starting Service")
    dim LS as new ListenerClass
    LS.Start
    end sub

    private class ListenerClass
    public sub New()
    dim client as new ClientClass
    end sub
    end class

    private class ClientClass
    public sub New()
    'blah blah blah
    'CODE NEEDED HERE TO CALL ON THE raiseevent internal message of ServerClass that was defined as FTP by the console application
    end class
    end class

    so basically what im trying to do is, get the ClientClass to invoke the event of a an instance of serverclass. or ie. its Parent Class.
    HELP PLEAAASE
    Or if you have any other method of transporting messages "upwards" of the object hierarchy please do advise.
    (and NO i dont want to pass down a "reporting type" object all the way down each time a new class is created.)

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: RaiseEvent and Classes (need expert's help)

    I will assume you left code out, but where are your declarations for your private classes in ServerClass? They need to be exposed to calling classes somehow.. right now (in the way you have posted your code) they are private and can't be created or used by anything but ServerClass itself.

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    7

    Re: RaiseEvent and Classes (need expert's help)

    Quote Originally Posted by kleinma
    I will assume you left code out, but where are your declarations for your private classes in ServerClass? They need to be exposed to calling classes somehow.. right now (in the way you have posted your code) they are private and can't be created or used by anything but ServerClass itself.
    yeah thats what I made it like.
    only the serverclass creates the private classes.
    the internal classes arent exposed.
    I did this so that everything is in a way "automated" and all the mother application has to do is call the startservice method.

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    7

    Re: RaiseEvent and Classes (need expert's help)

    I forgot 2 add a few lines, srry about that.
    heres the proper stucture of the ListenerClass

    Class ListenerClass
    public sub new()
    end sub
    public sub Start()
    dim client as new ClientClass
    client.dosomething
    end sub
    end class


    srry bout that guys.

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: RaiseEvent and Classes (need expert's help)

    You would need to put the events you want raised to the main application in the ServerClass then, and when the private class events are raised, handle that in the ServerClass, which in turn raises the event to the main app.

  6. #6

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    7

    Re: RaiseEvent and Classes (need expert's help)

    Quote Originally Posted by kleinma
    You would need to put the events you want raised to the main application in the ServerClass then, and when the private class events are raised, handle that in the ServerClass, which in turn raises the event to the main app.
    oh damn nice idea, didnt think of that.
    nice nice, thx, ill give it a try.

    ----------------30 mins later----------------------------

    ok im obviously doing something wrong here. erm could u give me a sample please?


  7. #7

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    7

    Re: RaiseEvent and Classes (need expert's help)

    man i wish i could post my source code, but its all on my laptop and im @ work right now, not allowed to transfer any files onto the office comps. =\

  8. #8

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    7

    Re: RaiseEvent and Classes (need expert's help)

    ps. im trying to pass a string from the ClientClass to the ListernerClass to the ServerClass and finally to the console app

  9. #9

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    7

    Re: RaiseEvent and Classes (need expert's help)

    basically what i did was add a subroutine in each class called "MessageService"

    Private Sub MessageService(byVal theMsg as string)
    raiseevent internalmessage(theMsg)
    end Sub

    and whenever i create a ClientClass from within the ListenerClass i do this

    dim newClient as new ClientClass
    addHandler newClient.InternalMessage, AddressOf MessageService

    i tried changing the AddressOf MessageService to Me.MessageService
    but that didnt work either
    I'm not getting any errors or anything, and the Events of the ListenerClass and ServerClass aren't getting invoked, I tried adding stops to check if they were being invoked.
    so basically
    when i do this from the ClientClass

    its supposed 2 invoke a subroutine in the ListenerClass which raises its internalmessage event, which causes a subroutine in the ServerClass run which finally triggers the internalmessage event of the serverclass which is picked up by the console app.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width