Newbie Question

J

JC7

Sorry if this question seems naive:
I'm writing a Windows Forms application in which all UI code is in the
Form1 class (controls added using the designer and event handler code
added by me).
My intention was to create a second class (called MasterDeviceControl)
which would contain functions to create addtional worker threads and
perform device IO through the parallel port using data in global
variables which are set by the user through Form1.
I put a "Start" button on Form1 and placed code in its' event handler
function to create a new object of my MasterDeviceControl class. The
constuctor of this class creates a new thread passing a reference to
MasterDeviceControl::DoWork function which then goes about the task of
device IO.
Everything works OK so far but I have run into problems when trying to
send information back to Form1 to confirm that things are working. I
want to use the statusbar at this point just for testing purposes and
I know that I cannot access this from any thread but the one on which
Form1 is running.
I created a delegate in Form1 which simply calls an updateStatusbar
function passing in a String pointer. I want to call Invoke on the
delegate from the worker thread.
How/where can I define the code for the MasterDeviceControl class in
such a way that it can refer back to the Form1 delegate??

If I get rid of the MasterDeviceControl class altogether and place
its' functions into the Form1 class, create the new thread in there
and call the delegate from that thread everything works.

I think I am just not understanding some very fundamental aspects of
oop in C++ and class relationships.

Thanks.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top