We create a ThisApp object. When it Inits it we pass a few parameters such as has a Qualifier, EnableUI and such. During Init we run an AddHandlers method and then an AddConnections, and AppProperties, MenuHandler, ToolBarHandler, etc. (With EnableUI = .F., we don't need the MenuHandler, etc.)
So for example, one of the handlers is a Connections collection. In AddConnections() we have a default way to determine the connections to add.
We never refer to the handlers again. If I pass a CursorAdapter class to ThisApp.GetConnections(), it gets a StatementHandle or it returns .f. and the CurorAdapter's Message property is set. If I run ThisApp.Launch('frmMyForm","MyApp.VCX"), a form is displayed. Of course the application object doesn't do all of this on its own -- it enlists the help of a FormHandler, or Connections object, but all that is hidden from the developer. I call ThisApp.WriteToErrorLog(oError) and the error is written. I don't ever talk to the any of the handlers directly. In some applications I might set up quite a few handlers and in some hardly any.
BTW, the CursorAdapter class has a ConnectionKey that lets the Connections collection know which connection object to use. By default the DataSourceType is empty so the Application can determine if we are going to do ODBC or Native. In some cases I know a data retrieval class is always Native, so there I specify it. I can specify ThisApp.DataSourceType = "ODBC" and have an client/server app. If I specify ThisApp.DataSourceType = "Native", it uses native tables. Data objects specify the DataSourceType if they know, otherwise the application decides.
>Hi Experts,
>
>I have a question re best practices on creating an Application Object.
>
>Should objects coming from say a Connections Manager or Forms Manager be a member object of - already instantiated - by the Application Object like so:
>
>
>oApp = CREATEOBJECT ("myApplicationClass") --> also instantiates oFormsMgr, oConnMgr
>oApp.oFormsMgr.MyMethod()
>oApp.oConnMgr.SomeOtherMethod()
>
>
>or can exists 'stand-alone', like so:
>
>oApp = CREATEOBJECT ("myApplicationClass")
>
>IF NOT oApp.Connect()
> MESSAGEBOX( 'Unable to connect' )
> ** do whatever else
>ENDIF
>
>PROCEDURE Connect
> LOCAL llResult
> oConnMgr = CREATEOBJECT( 'myConnectionMgr' )
> llResult = oConnMgr.Connect()
> RETURN lnResult
>
>
>Thanks in Advance
>Dennis
Charlie