Navigation:  Samples >

Workspace Sample

Previous pageReturn to chapter overviewNext page

This example creates a new Workspace and appends it to the Workspaces collection. It assumes that the user JustAUser with a password of Secret has already been created. The example enumerates the collections of each Workspace object and finally closes the new Workspace. See the methods and properties of the Workspace object or Workspaces collection for additional examples.

 

FUNCTION Start

LOCAL dbeng AS DaoDBEngine

LOCAL wrkNew, wrkEnum AS DaoWorkspace

LOCAL db AS DaoDatabase

LOCAL nWrk, nDb, nUsr, nGrp AS INT

LOCAL cSysDb AS STRING

set color TO w+/B

cls

dbEng        := DaoDbEngine{}

// Read location of System.MDW from Registry

// and use it

cSysDb        := DaoRegistrySystemDb()

IF ! Empty(cSysDb) .and. File(cSysDb)

 dbEng:SystemDb := cSysDb

ENDIF

 

// Open the database.

db := dbEng:OpenDatabase("\Vo2jet\Northwind.mdb",NIL,NIL,NIL)

 

// Create new workspace and add it to collection.

wrkNew := dbEng:CreateWorkspace("NewWorkspace", "Admin", "",NIL)

dbEng:Workspaces:Append(wrkNew)

 

// Enumerate all workspaces.

FOR nWrk := 1 TO dbEng:Workspaces:Count

   wrkEnum := dbEng:Workspaces:[Item,nWrk]

 

   ? "Enumeration of Workspaces: ", nWrk, wrkEnum:Name

   // Enumerate databases.

 

   ? "Databases: Name"

   FOR nDb = 1 TO wrkEnum:Databases:Count

       ? "  ", wrkEnum:Databases:[Item,nDb]:Name

 NEXT

   // Enumerate all user accounts.

   ? "Users: Name"

   FOR nUsr = 1 TO wrkEnum:Users:Count

       ? "  ", wrkEnum:Users:[Item,nUsr]:Name

   NEXT

   // Enumerate all group accounts.

   ? "Groups: Name"

   FOR nGrp = 1 TO  wrkEnum:Groups:Count

       ? "  ", wrkEnum:Groups:[Item,nGrp]:Name

 

   NEXT

NEXT

// Enumerate built-in properties of wrkNew.

 

? "wrkNew.Name: ", wrkNew:Name

? "wrkNew.UserName: ", wrkNew:UserName

wrkNew:Close()

wait