Site hosted by Angelfire.com: Build your free website today!

Original content from Real Gagnon's Site at http://www.rgagnon.com/pbdetails/pb-0133.html


Using the undocumented INDIRECT keyword

Unfortunately, knowledge of the INDIRECT keyword is generally missing from the PowerBuilder knowledge pool.  

General Application : Early development efforts in Powerbuilder tended to use public instance variables accessed from everywhere.  This was fast and easy, but you would get stung later when a value changed and your logic did "react" to the value change.  This lead to code being refactored into getter/setter methods.  This approach is still generally regarded as proper.  However, there is still quite a bit of that old code laying around.  Well, INDIRECT solves this dilemma by providing a great method for migrating from those public instance variables to getter/setter(s) without having to refactor all of the referencing routines.

Applicability to PFC : Starting in PowerBuilder 9, simple datatypes like integer, Boolean, and string when declared as public or protected instance variables become "properties" of those objects in descendents from an IDE standpoint.  This has the affect of encouraging developers to touch those properties directly as opposed to using get/set methods.  At one point, someone said that the PFC would be entirely different if this approach of descendent object "enabling" had been only a checkbox away.  While I agree, I can't help but wonder how the code would have worked correctly since the corresponding method (e.g. of_setBase(TRUE)) would never be called.

Simple example

[instance variable] public: INDIRECT string is_username {f_SetUsername(*value),f_GetUsername()} private: string PRIVATE_is_username [Powerscript functions] function integer f_SetUsername(string as_username) IF NOT IsNull(as_username) THEN PRIVATE_is_username = upper(as_username) END IF RETURN 1 function String f_GetUsername() RETURN PRIVATE_is_username [test] // the of_SetUsername() function is called by PB i_username = "powerbuilder howto" // the of_GetUsername() function is called by PB MessageBox("username", i_username)

PFC Version

public: INDIRECT BOOLEAN Enable_Base_Functionality {of_setBase(*value),_BogusIndirectGet()}

The _indirect_bogus_get is just to satisfy the requirement for a "getter".