The starting point for using FME objects is to create a FME object session object fmeosession, unless your applicationProgramTo operate on limited virtual memory, you can create a fmeosession object in the app initialization market and keep the object closed to the app, you can create a global session or access it through any object or method parameters.
Tip: A process can only have one session available. An error occurs when you try to create a second session.
In VB, you can use the Createobject method to create and return an ActiveX object. You can use this method to create a fmeosession object.
Set m_fmesession = Createobject ("fmeobjects. fmeosession ")
Once created, the fmeosession object must be initialized before use.Code:
Dim fmesessionsettings as fmeostringarray
Set fmesessionsettings = m_fmesession.createstringarray
Call m_fmesession.init (fmesessionsettings)
The following figure shows the attributes and methods of the fmeosession object:
All FME object acitvex objects are created using session objects. The following creates a string array object and assigns it to a variable.
Set fmesessionsettings = fmesession. createstringarray
The fmehome, fmeversion, and fmebuildnumber attributes can be used to understand the FME installation information.
In this chapter, we will learn:
- Initialize session settings
- Change session settings
- Capture Error
- Create a log file
- Configure functions and processors (factories)
Session settings
The configuration parameters of the FME object are the same as those of the FME object. For more information, see the FME configuration section in the FME Foundation manual.
Use the init method to set session parameters. For example, to set the temporary directory of the FME object, you can use the following code:
Dim fmesessionsettings as fmeostringarray
Set fmesessionsetting = m_fmesession.createstringarray
Fmesessionsettings. append ("fme_temp ")
Fmesessionsettings. append ("D: \ Temp ")
M_fmesession.init (fmesessionsettings)
After the session is initialized, you can use the updatesetparameters method to change the session parameters.
Capture Error
A good application should be able to capture runtime errors. It is best to restore errors without the user's knowledge, but no developer can predict all errors, A good design should be to capture errors and give user-friendly prompts when errors occur. The error capture of the FME object application is as follows:
Sub myprocedure ()
On Error goto error_handler
'Your code
'...
Exit sub
Error_handler:
If err. Number <0 then
Err. Number = err. Number XOR vbobjecterror
End if
Err. Raise err. Number, Err. Source, Err. Description
End sub
Tip: if an error occurs on the FME object, the fmeosession object becomes invalid and cannot be used in the application's lifecycle. to continue using the object, the application must recreate the fmeosession object.
To help you analyze runtime errors, the fmeosession object provides two attributes including diagnostic information:
Lasterrornum and lasterrorstacktrace. If your program has a log file, these two attributes can be recorded for easy diagnosis.
Tip: For simplicity, error capture is omitted in the sample program in this article, but we strongly recommend that you add it to your program.
Log File object
The fmeosession object allows your application to access the fmeologfile object of the session through the logfile attribute. You can use the fmeologfile object to name a log file.
The following code uses the Application Path and title to name the log file and write the Log Test information:
Public m_fmelogfile as fmeologfile
Set m_fmelogfile = m_fmesession.logfile
Slogfilename = app. Path & "\" & App. Title & ". log"
Call m_fmelogfile.setfilename (slogfilename, false)
Call m_fmelogfile.logmessagestring (0, "FME objects test .")
The fmeologfile object can write each piece of information to the log file to view the previously generated information. Call the holdmessage method. If the parameter is true, the log is sucked into the internal buffer. If the parameter is false, the buffer is stopped.
Set m_fmemessages = m_fmesession.createstringarray
Call m_fmelogfile.holdmessage (true)
Call m_fmelogfile.logmessagestring (0, "first message ")
Call m_fmelogfile.logmessagestring (0, "Second message ")
Call m_fmelogfile.holdmessage (false)
Call m_fmelogfile.logmessagestring (0. "Third message ")
Call m_fmelogfile.getheldmessage (m_fmemessages)
Function configuration
The FME function is exposed to the application through fmeopipeline and fmeofeature objects. The function configuration is described in FME functions, factories, and transformers. The fmeosession configure method allows you to specify the configuration for the function, the following code shows how to configure parameters for @ SQL functions.
Dim fmconfigrow as fmeostringarray
Set fmeconfigrow = m_fmesession.createstringarray
Fmeconfigrow. append ("SQL ")
Fmeconfigrow. append ("sampleconn ")
Fmeconfigrow. append ("server_type ")
Fmeconfigrow. append ("oracle ")
Fmeconfigrow. append ("SERVER_NAME ")
Fmeconfigrow. append ("sea_world ")
M_fmesession.configure (fmeconfigrow)
Destroy session
Once the session object is completed, you can destroy it:
Set m_fmesession = nothing
This will release all resources occupied by the session.
References:
Building applications with FME objects February 2005
Reprinted please noteArticleSource http://www.cnblogs.com/booolee