Group Object, Groups Collection and User Object, Users Collection Example (VC++)

This example illustrates the use of the Group and User objects and the Groups and Users collections. First, it creates a new User object with the Name, PID, and Password property settings of "Pat Smith", "abc123DEF456", and "My Secret" and appends the object to the Users collection of the default Workspace object. Next, it creates a new Group object with the Name and PID property settings of "Accounting" and "UVW987xyz654" and appends the object to the Groups collection of the default Workspace object. Then the example adds user Pat Smith to the Accounting group. Finally, it enumerates the User and Group objects in the collections of the default Workspace object. See the methods and properties listed in the Group and User summary topics for additional examples.

CdbDBEngine         dbeng;
CdbWorkspace      wrkDefault;
CdbUser            usrTemp;
CdbGroup         grpTemp; 
long            intI, intJ;

wrkDefault = dbeng.Workspaces[0L];

// Enumerate all users.
for (intJ = 0; intJ < wrkDefault.Users.GetCount(); intJ++)
   {
   usrTemp = wrkDefault.Users[intJ];
   printf(_T("Enumeration of User: %s\n\n"), usrTemp.GetName());

   // Enumerate groups.
   printf(_T("   Groups: \n"));
   for (intI = 0; intI < usrTemp.Groups.GetCount(); intI++)
      printf(_T("   %s\n"), usrTemp.Groups[intI].GetName());
   }
// Enumerate all groups.
printf(_T("\n------------------------------------\n\n"));
for (intJ = 0; intJ < wrkDefault.Groups.GetCount(); intJ++)
   {
   grpTemp = wrkDefault.Groups[intJ];
   printf("Enumeration of Groups: %s\n", grpTemp.GetName());
   // Enumerate users.
   printf(_T("   Users: \n"));
   for (intI = 0; intI < grpTemp.Users.GetCount(); intI++)
      printf(_T("   %s\n"), grpTemp.Users[intI].GetName());
   }