PFC Guide Titlebar
HomeFAQLinksPFCMAGExtensionsDownloadWhat's NewSearch

PFC 6.0 Most Recently Used Service

Page 3 of 3



... continued from page 2

Window lw_frame, lw_window
n_cst_menu lnv_menu
n_cst_mruattrib lnv_mruattrib

// Check parameters.
IF IsNull(ai_row) THEN
	Return -1
END IF
IF NOT IsValid(gnv_app.inv_mru) THEN
	Return -1
END IF
// Retrieve row from DataStore.
gnv_app.inv_mru.of_GetItem &
   (ai_row, lnv_mruattrib)
// Get the MDI frame, if necessary.
lnv_menu.of_GetMDIFrame(this.menuid, lw_frame)
OpenSheet(lw_window, &
   lnv_mruattrib.is_classname, lw_frame)
Return 1

Your version of the code in this event will depend on the approach you have accepted for opening windows within your application. Please note that when using a Non-Exclusive mode this event may be triggered for windows of a class different from the class of the current window. Therefore, the parameter passing method has to be generic enough for multiple window classes.

As with the previous events it is possible to move this code into the w_sheet, w_frame, or w_master ancestors.

 

pfc_MRURestore

Pfc_MRURestore is a placeholder event, used to restore the MRU settings. It was left empty to allow the end-user to specify a specific group ID. To restore the settings add a call to the of_restore() function passing the MRU ID as an argument.

string	ls_id
If IsValid(gnv_app.inv_mru) Then
	Return gnv_app.inv_mru.&
	of_Restore( ls_id, This ) 
Else
	Return 1
End If

One way to allow a more generic MRU implementation is to add an is_mruid instance string variable to the w_master window. If any descendant needs to participate in MRU service the variable may be set by using of_setMRUID() function. A sample generic pfc_MRURestore code is shown below

If IsValid(gnv_app.inv_mru) And &
    Len(is_mruid) > 0 Then
	Return gnv_app.inv_mru.&
	of_Restore(is_mruid, This ) 
Else
	Return 1
End If

The same approach may be used to generalise other MRU event logic.

Limitations

The MRU service uses the INI file or the registry to save the persistent information between each call or between multiple application "runs". An obvious limitation imposed by the INI file or the registry is that MRU service can only save string parameters. In cases where the window is opened passing an object instead of a simple datatype, such as an attribute non-visual object, the data contained within that object has to be encoded into a string. This may be done in the pfc_preMRUSave event. The decoding logic should be added to the pfc_MRUProcess event. When using the encoding / decoding approach don’t forget the 100 character limit imposed by the MRU datastore dataobject. If needed increase the s_menuitemkey size in d_mruservice datawindow object. Couple of other limits are worth mentioning as well. The total size of the INI file is limited to 64K. A single INI key entry is limited to 4K. The value entry limits in the registry are much higher, going up to 1 Meg, however values above 2K are stored as separate files.

 

Other Considerations

The single argument version of of_register() function defaults to five MRU menu items. To specify a new default number of MRU menu items the of_SetItemCount() function may be used.

inv_mru.of_setItemCount(7)

If a different number of MRU menu item is required for each ID a second version of the of_register() function may be used.

inv_mru.of_register("employee", 8)

If more than five menu items are specified additional placeholder MRU menu items have to be added to the m_master menu.

As mentioned previously the MRU service will save the information in the INI file or the registry. If some of this information is proprietary you may want to encrypt it to hide it from prying eyes. The MRU object has two events that are perfect for the encryption / decryption logic. The pfc_encode event in the pfc_n_cst_mru contains logic to combine the MRU entry information into a string to be saved in the INI or the registry. Pfc_decode event us used to parse the string. Extending these events offers an opportunity to add any required encryption routines.

Conclusion

Out of the box it may seem that it takes a lot of code to configure the MRU service. However, the reason for the apparent complexity is that PFC developers were not willing to enforce any behaviour restrictions on every PFC user. After making a couple of assumptions, most of the MRU configuration code can be moved into the framework ancestors and configuration code greatly simplified. Prior to using the service it would be wise to go through the checkpoint below:

  • Determine when the MRU information should be saved.
  • Set standard names for the Exclusive and Non-Exclusive ID’s or declare an ancestor window instance variable to allow each window class to specify the MRU group ID.
  • Implement a generic way to open windows and integrate it with the MRU service.

The MRU service can give your application the professional feel and ease of navigation found in many standard windows applications. With a little up-front work the service can be easily integrated into your framework or application.

Who said PFC took all the fun out of programming?

BulletSquiggle.gif (270 bytes)

About the Author


powertimes.gif (11989 bytes)

This article was originally  published in the April 98 issue of PowerTimes magazine.  To find out more about PowerTimes visit their website at http://www.powertimes.com/  

Last revised: February 15, 2004 03:58 AM.