PB未公开的特性:用indirect申明对象属性

在Google论坛上看到这个帖子,介绍PB中indirect语法的用途。这个特性对提高代码可读性和面向对象特点非常有帮助,可以实现VB中的 Property Get, Property Set 属性声明语法。


 

Michael Walker 
Cascadia Software

 

 

PowerBuilder does have an unsupported feature know as indirection. Indirection allows you to define an accessor (get) and modifier (set) function where you define your instance variable. Then when a developer modifies the instance variable, the functions get called behind the scenes.

 

I can't stress enough that this is unsupported, you will not get any tech support if this causes problems, and Sybase can remove this feature at any time.

 

I do know that it works on version 4 - 7. I haven't tried it yet on version 8. Here's how it works...

 

Declare your instance variables like the following

 

Public: 
Indirect String is_Name{ of_setname( *value*), of_getname()} 


Private: 
String is_Private_Name

 

In effect what this does, is create two instance variables, one public named is_Name, and one private named is_Private_Name. Now you will need to create the of_setname and of_getname functions, like you normally would, that modify or return the value of is_Private_Name. Of course you can put any validation you want in those functions to stop certain modifications to the value. So if a developer writes the following code...

 

ObjectReference.is_Name = "Mike" //This code will call of_setname

 

and that is how it works. It's pretty cool except that it is unsupported. There were minor issues in PowerBuilder 4, where you couldn't do this in a case statement or a messagebox but I know both of those issues were fixed in PB 5 and 6. I would certainly pay extra attention when testing this area.

 

Good Luck

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值