gettingstarted
[Top] [All Lists]

RE: How to call a method in a window from a TCPSocket

To: "'Getting Started'" <gettingstarted at lists dot realsoftware dot com>
Subject: RE: How to call a method in a window from a TCPSocket
From: "POIDINGER, Michael [JJRAU]" <MPOIDING at MEDAU dot JNJ dot com>
Date: Fri, 1 Apr 2005 09:17:40 +1000
Delivered-to: gettingstarted at lists dot realsoftware dot com
> -----Original Message-----
> From: gettingstarted-bounces at lists dot realsoftware dot com 
> [mailto:gettingstarted-bounces at lists dot realsoftware dot com] On 
> Behalf Of jdossey at att dot net
> Sent: Friday, April 01, 2005 3:48 AM
> To: gettingstarted at lists dot realsoftware dot com
> Subject: How to call a method in a window from a TCPSocket
> 
> I have a subclass of TCPSocket that I call MyTCPSocket.  In 
> MyTCPSocket I have some code in the Connected, DataAvailable, 
> and Error Events.  In DataAvailable I want to format the data 
> received, and then pass that formatted data to another method 
> which is in the main window.  And, I might have more than one 
> copy of the main window open, and each one has it's own copy 
> of MyTCPSocket - which I dragged to the main window in the 
> IDE.  The copy of MyTCPSocket in each window is called 
> MyTCPSocket1.  How do I call a method that is in the window 
> from MyTCPSocket1?  I've tried using "self.ProcessIt", but I 
> get a "this method or property doesn't exist" error message.  
> I could call ProcessIt using the window name like this 
> "Window1.ProcessIt", but will it call the ProcessIt method 
> for the correct window if I have multiple copies of Window1 
> open at the same time?

No it will not.

> 
> I know that I can copy the Event handler code from 
> MyTCPSocket to MyTCPSocket1, but then I have to copy that 
> same code to every different type of window that I create 
> that uses MyTCPSocket.  That's what I'm doing now.  I'd like 
> to just keep the code in MyTCPSocket.
> 

Create an interface which declares ProcessIt, and add it as an interface to
your windows

Add a Window property to your MyTCPSocket.

property WinRef as Window

In the open code of your windows, put

MyTCPSocket1.WinRef = me

then in your event you can have
MyInterface(WinRef).ProcessIt


If you only have 1 window, then you don't need the interface, just declare
the WinRef property as type Window1

Also I have tested nnon of the above code.  But I think it should work

Mike
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>