This example code creates an array of all AppClasses in an AppPackage. Useful for some patterns that use multiple classes of the same type.

The crux of this is some SQL:

select appclassid
from psappclassdefn
where packageroot = :1
and qualifypath = :2
and appclassid <> :3

This all assumes an interface, and that all AppClasses in the AppPackage are of this type.
The Array is an array of the same interface.
The SQL filters out the interface itself: and appclassid <> :3

class ArrayOfAppClasses
   method get(&packageRoot as string, &path as string, &interface as string) returns Array of APIObject;
end-class;   

method get
   local Array of APIObject &AppClasses= CreateArrayRept(CreateObject(&packageRoot | ":" | &path | ":" | &interface), 0);
   Local SQL &AppClassesSQL = CreateSQL("select appclassid from psappclassdefn where packageroot = :1 and qualifypath = :2 and appclassid <> :3", &packageRoot, &path, &interface);
   Local string &appClass;
   While &AppClassesSQL.Fetch(&appClass)
      &AppClasses.Push(CreateObject(&packageRoot | ":" | &path | ":" | &appClass));
   End-While;
   return &AppClasses;
end-method;

If your classes take parameters when creating you’ll need to mod or extend or whatever the above to use CreateObjectArray(Class_Name, Array_of_Args) instead.

I’ve just slapped the above together, mainly so that I can recall the SQL involved in future. I haven’t even tested it. Should be close though, and the main bit is really the SQL.