Creating an instance of MLSync

You do not have to use the MobiLink Synchronization Wizard to create a nonvisual object that launches Dbmlsync.exe. You can include an MLSync system object in your applications:

Adding an MLSync object programatically

The code fragment below creates an instance of an MLSync object and programmatically populates all of the necessary properties—as well as some optional properties—using an instance of the system SyncParm structure. Then it calls the Synchronize function to start the database synchronization.

SyncParm			Parms
MLSync			mySync
Long			rc

mySync = CREATE MLSync
mySync.MLServerVersion = 11		// required property
mySync.Publication = 'salesapi	'// required property
mySync.UseLogFile = TRUE		// optional
mySync.LogFileName = "C:\temp\sync.log	"// optional
mySync.Datasource = 'salesdb_remote	'// required
Parms.MLUser = '50			'// required
Parms.MLPass = 'xyz123			'// required
//The following values are required if they are not 
//set by the DSN
Parms.DBUser = 'dba		'
Parms.DBPass = 'sql		'

//  Apply the property values to the sync object
mySync.SetParm(Parms)	
//  Launch the synchronization process
rc = mySync.Synchronize()	
destroy mySync

Adding an MLSync object from the New dialog box

You can add an MLSync object to a target PBL using the New dialog box: from the PowerBuilder menu, choose File>New, go to the PB Object tab, select Standard Class, then MLSync. This opens a new MLSync object in the User Object painter, where you can initialize all or some of the properties. When you are finished, you can save it as a new object in your target PBL.

Since all of the properties are already initialized, including userids and passwords, it is ready for immediate use. To launch a synchronization requires very little coding, as this example for an MLsync object that you save as “nvo_my_mlsync” illustrates:

nvo_my_mlsync 		mySync
Long		rc
mySync = CREATE nvo_my_mlsync
mySync.Synchronize()
destroy mySync

You would typically add the above code to the Clicked event for a menu item or a command button on one of the application windows.

For more information

For more information on system objects related to synchronization, and their functions, events, and properties, see MLSynchronization, MLSync, and SyncParm in the online Help.