Problem with form instances (C#, CF.Net and VS2005)

mjohnson3091

Freshman
Joined
Aug 10, 2004
Messages
31
Location
Lancashire, UK
Hi all,

First of all let me say that i'm a real novice with VS2005 and mobile apps.

I've got a real problem with an application in VS2005 for Compact Framework 2 on a device running PocketPC2003.

I'll try to explain the problem....

I have a number of forms that "communicate" to a backend server through a single form (I'll call it Main for identification purposes). These other forms could be menus or function screens. On creation of each form, I create an instance member for that form and for the main form as follows:

Code:
        //current instance of main form - for comms
        frmMain frmMainFormInstance; 

       //current instance of this form - for comms
        private static frmMenu InspInstance = null;

        public static frmMenu Instance()
        {
            if (InspInstance == null)
            {
                InspInstance = new frmMenu ();
            }
            return InspInstance;
        }

I have a public routines in Main that will send and receive data and can be called from each other form using the instance of Main. So i can send data as below.

Code:
private void SendMessage(string strField, string strData)
        {
            
            frmMainFormInstance.SendData(
                strField + "" + Globals.cstFieldDelimiter + strData);
        }

When a response to a send is received in main, it sends the data back to the public "ReadMessage" routine on the relevent form as follows:

Code:
frmMenuInstance = frmMenu .Instance();
frmMenuInstance .ReadMessage(strField, strResult, strData);

So far all this works fine......

The problem I have is when I come to work with any of the controls on the form, for example a label. In the ReadMessage routine on frmMenu, if I try to write some text to a label I get the message "TextAlign = 'InspInstance.label1.TextAlign' threw an exception of type 'System.NotSupportedException' " and this seems to be the same for all labels on the form. Even though VS2005 is deploying the "Message" DLL for the device, it doesn't give me anymore specific information about the error.

When it creates the initial instance and I can write to the labels without any problems.

I hope all that made some sense to somebody.

Any suggestions/advice would be really helpful.
 
mjohnson3091 said:
The problem I have is when I come to work with any of the controls on the form...
So you are dealing with two different environments, one where it works, and one where it doesn't? Is it possible that not all parts of the .Net framework (i.e. the compact framework parts) were installed on your work machine? Could there by any other differences in the build environment between the machines that works and the one that doesn't?
 
mskeel said:
So you are dealing with two different environments, one where it works, and one where it doesn't? Is it possible that not all parts of the .Net framework (i.e. the compact framework parts) were installed on your work machine? Could there by any other differences in the build environment between the machines that works and the one that doesn't?

Hi, thanks for the reply.

I'm running both VS2003 and 2005 on the same laptop, and don't appear to have any problems.

I'm beginning to think it's something to do with the bit of code where I use a static variable to hold a reference to the form. If I watch the reference in the calling form, I can see from there that it already has the exceptions on the labels, like the form hasn't been instantiated iteself - it's really wierd.


I'm still working on it, but it's getting to the point where I'm going to give up and carry on with VS2005.

Thanks again.
 
Back
Top