现在的位置: 首页 > 综合 > 正文

PB窗口上控件间的继承,一个奇怪的问题

2013年07月21日 ⁄ 综合 ⁄ 共 1415字 ⁄ 字号 评论关闭

今天在分析一个文件,遇到它窗口上某个控件的datatype是另外一个控件的情况。也就是在同一个窗口上,一个控件继承自另外一个控件。

起初以为我的 PB DeCompiler 存在问题,结果用PBkiller和Shudepb分析结构都是一样。

我想到这是不是形同继承的写法,如果只有一处倒可以怀疑编译时出问题了。不过多个窗口都出现这个现象。遂在PB中自己测试,也是可以的:

 

forward
global type w_9 from window
end type
type cb_2 from commandbutton within w_9
end type
type cb_1 from cb_2 within w_9           //cb_1 本来是来自commandbutton,我手工改成cb_2
end type
end forward

global type w_9 from window
integer width = 3168
integer height = 1464
boolean titlebar = true
string title = "Untitled"
boolean controlmenu = true
boolean minbox = true
boolean maxbox = true
boolean resizable = true
long backcolor = 67108864
string icon = "AppIcon!"
boolean center = true
cb_2 cb_2
cb_1 cb_1
end type
global w_9 w_9

on w_9.create
this.cb_2=create cb_2
this.cb_1=create cb_1
this.Control[]={this.cb_2,&
this.cb_1}
end on

on w_9.destroy
destroy(this.cb_2)
destroy(this.cb_1)
end on

type cb_2 from commandbutton within w_9
integer x = 658
integer y = 580
integer width = 457
integer height = 128
integer taborder = 20
integer textsize = -12
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
string text = "none"
end type

event clicked;messagebox("xx","ddd")
end event

type cb_1 from cb_2 within w_9    //cb_1 本来是来自commandbutton,我手工改成cb_2
integer x = 663
integer y = 408
integer taborder = 10
end type

event clicked;call super::clicked;messagebox("2","2")        //这里看它call了祖先事件。实际运行测试,cb_1按下时是可以先执行cb_2的messagebox,再执行自己的messagebox
end event

 

也许这样写是可以,但我不知道,有知道的请告知我一下。谢谢。

对了,这种写法的好处是可以用一个按钮完成大部分功能,用其他几个按钮提供扩展功能。避免代码重复,冗长累赘。

 

抱歉!评论已关闭.