Passing the workspace as a parameter

From DataFlex Wiki
Revision as of 10:59, 20 February 2008 by Wil (talk | contribs) (→‎The program)
Jump to navigationJump to search

Parameter to choose workspace used

Previously in VDF 11.1 I have created and compiled programs on my development machine with local data on drive C:and a workspace called "Garments". When publishing the program for network use, I have passed a parameter to the application "Netgarments" and have had a separate "Netgarments.ws" file which stated that the data path was on drive F: - the network drive. Thus when using the App on the network, users saw data on drive F:

How can I do this with the new workspace system in VDF12.x and beyond?

Changes in the cApplication class

With VDF12 the workspace logic has changed a little. Previously in VDF8.x .. VDF11.x the configuration of your workspace was partly stored in the registry and partly in the .ws file. Now with VDF12.x (and later) the registry settings are gone. The settings are now stored in a .sws file along with one (or more) .ws files.

In order to select the correct .ws file, the cApplication class now has a property called

psAutoOpenWorkspace

and its default is

config.ws

which is the name of the default .ws file. If you want to use your old .ws file, just change the value of that particular property.

The program

the program:

//AB-StoreStart
Use dfAllEnt.pkg
use DFAbout
//
#REPLACE CURRENT$WORKSPACE   "Training.Mapps121" //default - modified by calling param
Register_Object oClientArea
//
// 1) use package for application workspace
Use MyApplication.pkg //Workspc for multico workspace mapps121
//
// 2) Set date attributes as needed
Set_Date_Attribute sysdate4_State to dftrue
Set_Date_Attribute Date4_State    to dftrue
Set_Date_Attribute epoch_value    to 60
//
// 3) Application Workspace - help type and name
Object oApplication is a cMyApplication
End_Object  // oApplication

The cApplication subclass

 Class MyApplication is a cApplication
   Procedure OnCreate
       String sCompanyFolder stemp Programname
       cmdline sCompanyFolder
       If (sCompanyFolder="") Move "TRAINING" to scompanyfolder //default to traing db if execeuted without param
       move (uppercase(sCompanyFolder)) to sCompanyFolder
       
       
       Send DoOpenWorkspace (sCompanyFolder -".mApps121") //CURRENT$WORKSPACE
       
       Get_Attribute DF_OPEN_PATH to sTemp        
       //Showln sTemp
       
       Open refnum2
       Move (trim(refnumA2("COMPFOLD"))) to sTemp //function to get a param form the correct company control file
   
       If (sTemp<>sCompanyFolder) Begin
           Send stop_box ("Company ID mismatch in refnum2 file"  * sCompanyFolder * sTemp) //dont show, it would be a security weakness
           Abort //showstopper
       End
       Set psCompanyFolder to sCompanyFolder
       
       Move (trim(refnumA2("COMPCOLR")))   to sTemp
       Set psCompanyColour to sTemp
       Set Color to clYellow
       
       Move (trim(RefNumA2("COMPANY")))    to sTemp
       Set psCompany  to sTemp
       
       Set peHelpType to htHtmlHelp
       Set pbEnterKeyAsTabKey to True
       Set psProduct to "KirkNet"
       Set psProgram to (Module_Name(Self))
       Set psHelpFile to ((Module_name(self)) + ".htm")       
       Set pbPreserveEnvironment to False          
   End_Procedure
 End_Class