Monday, January 17, 2011

PEM Editor tip: Cross References screen (new feature)

This is a new feature in version 6.50.

The Cross References screen (see sample below) creates an analysis of all of the 'names' referenced in a PRG, method, or collection of methods.  These names are broken down into about a dozen different categories;  the TreeView on the left provides for navigation between the categories and the names within each category, and the grid on the right shows where the names are referenced.  Double-clicking on a row in the grid opens the indicated method and highlights the relevant line of code.

Invoking the Cross References Screen

For PRGs and single methods, the Cross References screen is accessible either from the PEM Editor menu in the VFP Main Menu, or by using a hot key (assigned in the Preferences screen).

For forms and classes, the Cross References screen may be applied to all of the custom methods for a class or an object, or for an object and all of its child objects.  The option to do so is found in the right-click context menu for the combobox.

Analysis / Categories in the TreeView 

The Cross References screen breaks the 'names' referenced in code into about a dozen distinct categories.  The 'names' actually include extended names, so that references to objects ('This.lblName.SomeProperty') or tables ('Customers.Name') are treated as single references.  Furthermore, references within WITH/ENDWITH blocks are resolved to point to the object named in the WITH statement.  (This even applies to embedded WITH/ENDWITH blocks).

The categories and their definitions are:
  • Global Assignments - simple names that are assigned values, but are not locals or parameters
  • Global References - simple names that are referenced, but are not locals or parameters
  • Tables/Cursors - references to names in VFP statements that indicate a table or cursor
  • Fields - references to names in SQL-Select statements
  • Forms - Do Form .....
  • Procedures/Functions -Calls to PRGs, or procedures or functions within PRGs.
  • Methods - Calls to methods
  • Property Assignments - references to properties or objects that are assigned values
  • Properties/Objects - references to properties or objects that are not assigned values
  • Parameters
  • Locals
  • Constants - compiler constants (#Define ...)
Warranty Information: This categorization cannot be perfect -- it is only at run time that VFP itself can properly identify which category any name falls into.  While the first two and last three categories are completely reliable (global assignments and references, parameters, locals, and compiler constants), the remainder cannot be, and so there are instances where names will be reported in the incorrect category.  For instance, 'Customers.Name' certainly looks like a reference to a field in a table, but 'Customers' could (conceivably) actually be an object reference.

The Grid

The four columns may be moved or resized them as desired; their size and order will be remembered for next time.

The grid displays one record for each line of code that a name is referenced on.  If you double-click on one of the records, the method/PRG will be opened and the line of code will be displayed.

There is a possible point of confusion when references are to code that is created on continuation lines.  The analysis of code in this screen treats code on continuation lines as a single line of code.  Thus, double-clicking to a reference in the grid will always highlight the first line in a set of continuation lines, even if the actual reference is to a later line in that subset.


There is a right-click context menu for the TreeView that allows for some customization:
  • You can select which of the categories are automatically expanded when the screen is first opened.  (By default, all categories are collapsed).
  • You can select which single category is initially selected when the screen is first opened (causing the references to the items in that category to appear in the grid.

1 comment: