在pb中有一個沒有公佈的關鍵字INDIRECT,其功能是將變量與方法進行綁定,可以在對變量進行賦值或取值時執行相應的函式.
[instance variable]
public:
INDIRECT string i_username {of_SetUsername(*value),of_GetUsername()}
private:
string zis_username
[Powerscript functions]
function integer of_SetUsername(string as_username)
IF NOT IsNull(as_username) THEN
zis_username = upper(as_username)
END IF
RETURN 1
function String of_GetUsername()
RETURN zis_username
[test code]
// 執行下列賦值語句,則會調用of_SetUsername()函式
i_username = "powerbuilder howto"
//執行下列取值語句,則會調用of_GetUsername()函式
MessageBox("username", i_username)