|
Comments
|
Today's Top SOA Links
PowerBuilder PowerBuilder - The ClassDefinition Object
...or how to create a simple object browser - Part 2
By: Arthur Hefti
May. 19, 2006 11:15 AM
In the first article we presented a some theories about the ClassDefinition object and were able to show the libraries of a PB application in a treeview control. This month we'll read the objects from the libraries and inspect their content.
If it wasn't expanded already, we check to see if the level of the treeviewitem is equal to two, which means we're expanding a library name. We could create an NVO to include all the logic for parsing, but for demonstration purposes, I want to keep things simple. We define all the functions we need on the window itself, but use arguments to refer to the controls. This will let you move the logic to an NVO quite easily later. The next function we create is called of_ShowLibraryItems. It's used to read the PB objects from a PBL. I use the function LibraryDirectoryEx to extract the objects. Compared to the function LibraryDirectory, it provides the date/time modified and the comment as well as the name and type of the objects. Since I want the objects sorted, I use a DataWindow with an external datasource. See Figure 1 for the definition of a DataWindow. Set the sorting to the column objtype and save it as d_libobj. The string returned byLibrary-DirectoryEx will be imported into the datastore by the ImportString. After sorting the data, the script loops through the objects and adds them to the treeview. You can find the code for this function in Listing 1. Call the of_ShowLibraryItems function in the itemexpanding event of the treeview control when the level is 2, whereas the ll_TviCurrent is the treeviewitem identified by the handle argument. Parent.of_ShowLibraryItems( This, handle, ltvi_Current.Data )
On to Class Details It's impossible to loop through the variable list of the ClassDefinition object of a PB object and display all the information about it nicely. So the next step is creating two helper functions. The first is called of_ValueString and translates the enumerated values to strings (see Listing 2). The arguments of this function are the type of a variable (e.g., Cardinality or InitialValue) and the value itself. It returns both as a readable string. Converting the value to a string is simple with, say, Boolean values; however if we have enumerated data types we have to handle them individually. If the variable is an enumerated datatype we use the FindTypeDefinition get all the possible enumerations of this datatype. The second function is called of_FormatInfo (See Listing 3) and takes a classdefinitionobject as its argument. Its purpose is to create a formatted string out of the classdefinitionobject information. The argument is a classdefinitionobject type, which lets us pass variables of type classdefinition, scriptdefinition, and variabledefinition.
Display the Information about a Class
ll_Child = This.FindItem( ChildTreeItem!, handle )
END IF Then the nested classes are shown. The naming convention of a nested class is objectname`nestedclassname. We need the whole name to find more information about the nested class when calling FindClassDefinition. For nested classes we check the property ParentClass. If this is null we don't add the class. Further the NestedClassList returns not only the controls on an object, but also the controls on the ancestor of the object. We prevent showing ancestor data by comparing the name of the ParentClass of the NestedClass with the name of the current object. If they don't match, the control is inherited from the ancestor. At the end of this list we add an entry for the ancestor object if there is one. To display the additional information stored in the data property of the treeview items you have to put the following code in the selectionchanged event of the treeview:
treeviewitem ltvi_Current When running the application and expanding a library entry, all the information of the entry itself is loaded at once. We don't parse information about nested classes and no information about possible ancestors is retrieved (except its name). On large objects this might take some time. To drill down on an entry you have to expand the item in the treeview. If it's a nested class or ancestor class and the data isn't loaded, the ClassDefinition object of the chosen entry is retrieved by FindClassDefiniton and the function of_ShowClassDefinition is called, passing the ClassDefinition object as an argument. Since the ClassDefinition object is available to all PB classes, no further coding is required and our application is ready to browse. Browsing PFC-based applications is quite interesting and lets you drill down many levels. You can download the source code of the application from the PBDJ Web site or from the download section of the CATsoft Web site at www.catsoft.ch.
Conclusion Reader Feedback: Page 1 of 1
Your Feedback
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
||||||||||||||||||||||||||||||