call a window's method from a serial class

Background:

I have a subclass of Serial that connects to a particular serial device. I parse the data from the device in the subclass’ DataAvailable event.

I have 3 windows, each has a TextArea. In this application, only one window is possible to run at a any one time, selected by a mode meaningful to the application. Each window has a Property mSerial of the Serial subclass’ type.

Goal:

When the subclass’ DataAvailable has parsed a ‘packet’ of information from the device, I want to append this data to the currently active window’s TextArea. I’d prefer to have one Serial subclass that can make use of a method in the window, rather than tailor 3 subclasses each specific to a window but otherwise identical.

Request:

Please advise on how I might accomplish this.

Water under the bridge:

I’m suspecting I need something along the lines of a Delegate function, or maybe an interface. But I cannot wrap my head around the Delegate behavior. I have read the Xojo documentation, the User Guides, Howe’s OOP Programming, reviewed old NUG articles. I’m stumbling badly on this search. Rather than describe all the things I tried that didn’t work, I thought I’d back up and ask how you smart people might approach this issue.

Daniel

Define a new event in your mSerial class. (i.e. mySerialEvent) When the DataAvailable event has parsed the incoming data, call the defined event with
raiseEvent mySerialEvent(myData)
passing the data to the event.
In each Window’s instance of mSerial you will see the new event exposed. Have the window populate its own textArea(s) when that event is raised.

I think Roger means drag an instance of your serial class onto the window, instead of making it a property of the window and instantiating it in code. Then you will have access to its events in the window’s code editor.

Yea, what he said. :slight_smile:

Thanks, I’ve got it working now.

But now I’m curious.

Obviously, doing something like this by making the Serial subclass a property and instantiating it in code is “harder” than dropping the subclass on the window. But how much harder? If it is possible, would you offer some hints on how it would be accomplished, or a pointer or two to references?