请教pb的变量作用范围,与大家交流交流

xhzlhc 2012-12-15 06:57:13
我一直以为pb的变量只区分 share,instance,global,loacl 没有所谓的 public,private,protected这种分类的。
但是几天我看到某程序在 instance varible中这样写的

w_test
public:

string ls_t1 = ‘ok’

private:

string ls_t2 = 'hao'

我试了一下好像没啥区别,w_test中的任何控件 任何函数都能直接调用
...全文
941 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
PB菜鸟 2012-12-27
  • 打赏
  • 举报
回复
zhangyangziwo 2012-12-26
  • 打赏
  • 举报
回复
基本的面向对象的功能,还是支持的
fengge2663 2012-12-21
  • 打赏
  • 举报
回复
权限设置有作用了,非public,其他对象将无法引用,shara Variables和 Instance Variables的区别在于后者实例变量在作用实例本身,多个实例之间不产生影响。前者共享变量多个实例之间将产生影响。自己建立个用户对象进行测试下就明白。
core0 2012-12-20
  • 打赏
  • 举报
回复
学习了。。。
做梦的猫 2012-12-18
  • 打赏
  • 举报
回复
public: privateWrite int ii_test // 自己可以写,其它对象只能读
sjlion 2012-12-18
  • 打赏
  • 举报
回复
接分接分
Liu_cy88 2012-12-18
  • 打赏
  • 举报
回复
PowerBuilder的变量作用域共有四种:全局变量(Global Variables)、实例变量(Instance Variables)、共享变量(Shared Variables)和局部变量 全局变量 “”、“”和“” 全局变量在整个应用程序中都可访问,它的作用域是整个应用程序 。 实例变量 实例变量与对象相关联,只有在该对象的事件处理程序或函数中才能使用为该对象定义的实例变量。实例变量在它所关联的对象被打开时创建,被关闭时消失。 共享变量 共享变量是一种静态变量,这不仅意味着它所在的对象关闭后再次打开时,共享变量依然保持对象关闭时的值,而且还意味着同一个类多个实例中的同名共享变量保持相同的值。 局部变量 局部变量在使用它的事件处理程序或函数中说明,其作用域仅限于说明它的程序段,在该程序段的任何地方均可访问局部变量,但其它程序段都不能访问本程序段中的局部变量。运行程序后,进入某个程序段时,系统自动为局部变量分配内存,退出程序段时,局部变量占用的内存被释放。
xuam 2012-12-15
  • 打赏
  • 举报
回复
1.shared variable A variable that belongs to an object definition and exists across all instances of the object. Shared variables retain their value when an object is closed and opened again. Shared variables are always private. They are accessible only in scripts for the object and for controls associated with the object. Shared variables can belong to the Application object, a window, a user object, or a menu. 2.instance variable A variable that belongs to an object and is associated with an instance of that object (you can think of it as a property of the object). Instance variables have access keywords that determine whether scripts of other objects can access them. Instance variables can belong to the application, a window, a user object, or a menu. 3.global function A user-defined function that is not associated with any object in the application and is always accessible anywhere in the application. Global functions correspond to the PowerBuilder built-in functions that are not associated with an object, such as the mathematical and string-handling functions. 4.local variable A temporary variable that is accessible only in the script in which you define it. When the script is finished, the variable ceases to exist.
xhzlhc 2012-12-15
  • 打赏
  • 举报
回复
大家快来说两句 我好散分 哈哈 还有shared varib 也有点意思 相当于java中的private varib 感觉还是会用到的 比如窗口关闭了 还想获得关闭前某varib的值 这时候 就得用shared varib
xhzlhc 2012-12-15
  • 打赏
  • 举报
回复
哦 我知道了 新开一个w_test1
调用 w_test.ls_t1 没问题
w_test.ls_t2 报错 如下:

1,108

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧