|
Comments
|
Today's Top SOA Links
Techniques The ClassDefinition Object
Or how to create a simple object browser - Part 1
By: Arthur Hefti
Mar. 27, 2006 11:00 AM
The ClassDefinition object was introduced in PowerBuilder 6.0 a long time ago. It allows you to retrieve information for an object at runtime. Most of us didn't pay too much attention to this object and it only attracts our attention when we see it in the debugger.
The ClassDefinition Object Hierarchy The objects in Figure 1 serve the following purpose:
First Steps This.Title = FindClassDefinition( ClassName() ).LibraryName You can either run the window or open it in the application object. Running the application allows you to debug and inspect additional properties of the ClassDefinition object. I would categorize them into two groups. The first group contains properties describing the object. These are properties like Name, DataTypeOf, IsVisualType, etc. In the other group are properties that describe the data "within" the object such as NestedClassList, ScriptList, or VariableList and ParentClass for a NestedClass. Add a treeview control to the window, check LinesAtRoot, and put the code from Listing 1 into the open event of the window. First, we retrieve the ClassDefinition object and use the property name to add the window name as a first entry in the treeview. Now we loop over every variable of the window (stored in VariableList) and add the name of the variable as a child to the window name entry. With these few lines we already see some information regarding the variables of this window. In the script from Listing 1 we used the VariableList property (an array of VariableDefinitionObjects) that lists all the variables of a class. For a closer look at the nested classes of the window, use the NestedClassList property of the ClassDefinition object. The NestedClassList is an array of ClassDefinition objects describing the nested classes of an object (the treeview control in our example window). The code from Listing 2 shows the nested classes in the treeview. Play around by adding some more controls to the window. If you replace the NestedClassList in the script with the ScriptList property, which is an array of ScriptDefinition objects, the events and functions of the window are shown in the treeview. Let's use the script from Listing 1 and add the initial value of the variable to the treeview label. Add the following code for the label in the InsertItemLast function and run the application. + ': ' + String( lcd_Window.VariableList[ll_Counter].InitialValue) Behind each variable you'll see the initial value of the variable as long as the variable is a simple type and not an enumerated type, for example, toolbaralignment.
The Browser First we create a MDI frame window (w_frame) with a menu (m_frame) and a sheet window (w_main). Choose either an application icon or a library-related icon for the windows. The sheet requires no menu on its own. The main menu should include an entry File/Open and File/Exit. You can either create this from scratch or use the Template Application Wizard in the PowerBuilder IDE.
Getting the Library List
Save Format v3.0(19990112) For our application we need the keyword appname to determine the name of the application and the keyword liblist for the library list. In Listing 4 we parse the PBT file by looping through each line and check for the key appname. As soon as we find it, we remove the double quotes and set the title of the window to the name of the application. We continue looping until the key liblist is found. Having found the key, we can leave the loop and start parsing the line found. Each PBL entry is separated by a semicolon. We split the line and store each library as an entry in the il_LibList array together with the directory where it's located. Using PFC would have made some tasks easier but I want to keep the application small. Place a treeview control with LinesAtRoot checked on the left half of the window w_main and a multilineedit control on the right half of the window. You may add some code to resize them dynamically when the window size changes. We need quite a lot of treeview pictures in the application. Set the property PictureMaskColor to silver and define the pictures in the treeview and the picture constants in the instance variables section according to Table 1. Since we used the last picture of the control as an overlay picture, place the following code in the constructor event of the treeview control: This.SetOverlayPicture(1, PICT_OVERLAY) In the open event of the window w_main call the function of_ParseLibList. We pass message.stringparm as an argument to this function as this is the target file passed to the window w_main on opening it. The code to call the function and fill the treeview can be found in Listing 5. The name of the library is shown without path information as the path information is stored in the data property of the treeviewitem. The children property is set to TRUE to show the plus sign in front of the library entry. This allows the coding the drill down in the itemexpanding event. Next month we'll continue to work on the browser. We'll read the objects from the PBL and drill down on them. Reader Feedback: Page 1 of 1
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 |
|||||||||||||||||||||||||||