Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Understanding the application Factory
Message
De
11/05/2007 17:42:26
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Titre:
Understanding the application Factory
Divers
Thread ID:
01224861
Message ID:
01224861
Vues:
65
When you create a new mm windows application a factory.cs is created which is a subclass of mmFactoryDesktop.

In the MM.net Developers Guide it says the following:
The Factory is the only object to be automatically created when the application object is first instantiated.

The Factory is created in a method called CreateFactory which is called from ApplicationInit() within mmAppBase. Of course the mmAppDesktop overrides the CreateFactory Method and would create a mmFactoryDesktop however in our application object app.cs it is overriden to create a Factory() object.

If in the Load method of the main form I attempt to reference an object within the app.cs which uses the factory, the factory doesn't seem to exist yet.

In my MainForm_Load method
CPVSettings settings = AppDesktop.AppSettings;
GpsBase gps = AppDesktop.Gps;
if (settings.EnableGps)
{
     gps.Port = settings.GpsPort;
     gps.BaudRate = settings.GpsBaudRate;
     gps.Initialize(settings.gpsAutoConnect, settings.GpsDelayStart, settings.GpsDelaySeconds);
}
The second line fails. It references a static property in the app.cs (AppDesktop)which uses lazy instantiation and calls the factory like this.
public static GpsBase Gps
{
     get
     {
	if (gps == null)
	{
	     gps = factory.CreateGps();
	}
	return gps;
     }
}
private static GpsBase gps;
The AppDesktop includes this reference to the factory
static Factory factory = (Factory)mmAppBase.Factory;
As soon as we hit the factory.CreatGps() I get "Object reference not set to an instance of an object"
It is referring to the factory object.
If the AppDesktop essentially creates the factory on instantiation, why don't I have a reference to it?
Thanks for any help understanding this.
Tim
Timothy Bryan
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform