MSM-Workstation Tutorial (part 2/5)
Let's analyze what $$Init does. Window CommonCode Init() N Path,Result,Args,Sucess MSM-Workstation allows you to read and write data to the Windows 95 registry. You are only allowed to tinker the area applicable to your application. The function GETENTRY (part of the routine %mprof) lets you read a value into a variable. You supply the section, key and variable (observe the period before the variable name). The last parameter is an optional default value that will be stored in your variable if the entry is not found. It also returns (Result in our code) whether it was successful or not. In our case DBNAME must store within it database and path. If it is empty a new installation is assumed. We mentioned at the beginning that this program automatically handles a 2nd level installation. What we meant was that it lacks a procedure to to place the archive in a directory, register with Windows 95 the application, add an uninstall feature and create the necessary icons (for more on this check out our review of installers). But sets up and creates a database automatically. D
JustifyW^%ViEg1(%%CurrWin,$G(ViEWsets("PosJustifyH"),"C"),
$G(ViEWsets("PosJustifyV"),"C")) In the chunk above, we read from the registry the password. ; Check that the database does exists ; Force exit out of module as % % Cancel does not exit module and will therefore stop
due to an error if Sucess=0 Here we use the $ZOS function to check that the database physically exists (assume the user deletes it?) For an explanation of $ZOS check help or refer to the section at the end of this tutorial. Observe closely the comment line % % Cancel. If you join it up you will get an error during compilation because %%Cancel will be translated into code. Remember that macros can be applied anywhere (even within comments). We will discuss macros next time. ; Mount Database The chunk above calls function $$HOSTVOL^%msv(DBNAME,.VgNum,.VgName). It receives the Database path and returns (note periods) the Volume Group Number and Name id the database is mounted. If Result is +ve the database is somehow already mounted and we must therefore unmount it. S InParam("DBNAME")=DBNAME Next we must mount the database. There are three types of database mount functions: Local mount, remote mount and memory mount. Workstation provides a the function $$MOUNT that determines automatically whether the database is local or remote or in memory. To mount a database you must set up an array specifying the database parameters. A second array will contain the details of the mounted database. If the function returns a ve number the operation would have failed. See the section Mounting a database for in this tutorial more information. To see the above code in action, try running two instances of Tutorial.EXE. One important parameter is the Moniker (our database is given a moniker of MWMdb). This is the alias to our database. We will use this moniker to refer to the database. ;Get Free space and expand if necessary As we want our program to be self maintaining, we sometimes have to expand our database. The chunk above checks how many 1K blocks are free and expands as necessary. The code marked in Red changes the mouse pointer from the arrow to the hourglass and back. %%Set(TextBox1.Value,"Done.") This module finally returns the database name and path to the calling module. ; A new installation is detected. Create the database
allowing user to select path and define Whenever a new setup is detected this routine gets called. It calls window Install which in turn returns whether the operation was successful (1) or whether it failed (0). This is returned to the calling module. ;Return 1 if the correct password has been entered,
otherwise O
Window Destroy K DBNAME,DBPASS,Done Control Timer1 timer N DBNAME
Control Version Create N OutParam,String The library ^%mdlcnse stores information about your exe program (Check Help for more information). Many of the details can be filled in when you choose the Make EXE option. INFO^%mdlcnse fills up your array (notice the period) with some or all of the following:
Window Install The code in this window is quite simple to follow. One thing you should note is that we create too small a database which will need expansion immediately. This does not make sense and would have been better had we set the correct size initially. The reason for this approach is that we wanted to demonstrate the automatic expansion facility. The password boxes display asterisks. This is done automatically by defining the PasswordChar property of your textbox object. Other than the user interface change it can be manipulated like any other text box.
Check out Setup Push for information on how to write to the Windows 95 registry. Couple that with the Intro Window which reads from the same location.
|