首先说明一下,Powerbuilder并不包含像java和.net的下的完整反射机制。尤其是动态执行代码方面更是完全不行;本文介绍的主要内容是一些在实际的设计模式应用当中,可以模拟的反射功能。
1、ClassDefinition对象
ClassDefinition是powerbuilder自带对象基类的一个成员对象;主要作用是获取该对象的运行时信息。与之相关的对象继承关系如下:
、
ClassDefinition相关的功能和用法、属性;还是请各位自行查阅帮助文件。这里用ClassDefinition的功能,我们给大家模拟一下判断一个对象是否是某个类的具体实例。
函数名叫做
isinstanceof( powerobject apb , string as_type )
value
powerobject
apb
对象
value string as_type classname
value string as_type classname
try
ClassDefinition lcd_current
if isnull( apb ) or not isvalid( apb ) then
return false
end if
as_type = lower( as_type )
if as_type = "powerobject" then return true
lcd_current = apb.ClassDefinition
//判断类和父类
do while not isnull( lcd_current ) and isvalid( lcd_current )
if lcd_current.name = as_type then
return true
else
lcd_current = lcd_current.ancestor
end if
loop
return false
catch( runtimeerror er)
throw er
return false
end try
ClassDefinition lcd_current
if isnull( apb ) or not isvalid( apb ) then
return false
end if
as_type = lower( as_type )
if as_type = "powerobject" then return true
lcd_current = apb.ClassDefinition
//判断类和父类
do while not isnull( lcd_current ) and isvalid( lcd_current )
if lcd_current.name = as_type then
return true
else
lcd_current = lcd_current.ancestor
end if
loop
return false
catch( runtimeerror er)
throw er
return false
end try
这个函数能判断对象是否是你传入的classname的实例或者派生类的实例
2、ClassName方法
ClassName方法返回改对象的类型名称,有2中调用方法,比如窗口上有个不可使对象timeing_1
(1)ClassName( timeing_1 ) 返回的是timeing_1字符串,也就是你的timeing_1对象的真正全局名称,但是你是动态创建的不可视对象,返回的不是timeing_1,而是timing,很奇怪是吧,这个和powerbuilder的机理有关系,这里就不详细介绍,如果大家想了解的话,在窗口上列表上点右键edit source就能看到端倪。
(2)直接用timeing_1.ClassName()方法,执行结果同(1)
3、tpyeof方法
typeof方法返回的是一个object枚举值,object枚举值
accessibility!
adoresultset!
any!
application!
arraybounds!
blob!
boolean!
character!
checkbox!
classdefinition!
classdefinitionobject!
commandbutton!
connection!
connectioninfo!
connectobject!
contextinformation!
contextkeyword!
corbacurrent!
corbaobject!
corbaunion!
cplusplus!
datastore!
datawindow!
datawindowchild!
date!
datetime!
decimal!
double!
dragobject!
drawobject!
dropdownlistbox!
dropdownpicturelistbox!
dwobject!
dynamicdescriptionarea!
dynamicstagingarea!
editmask!
enumerationdefinition!
enumerationitemdefinition!
environment!
error!
errorlogging!
extobject!
functionobject!
graph!
graphicobject!
graxis!
grdispattr!
groupbox!
hprogressbar!
hscrollbar!
htrackbar!
inet!
integer!
internetresult!
jaguarorb!
line!
listbox!
listview!
listviewitem!
long!
mailfiledescription!
mailmessage!
mailrecipient!
mailsession!
mdiclient!
menu!
menucascade!
message!
multilineedit!
nonvisualobject!
notype!
objhandle!
olecontrol!
olecustomcontrol!
oleobject!
olestorage!
olestream!
oletxnobject!
omcontrol!
omcustomcontrol!
omembeddedcontrol!
omobject!
omstorage!
omstream!
orb!
oval!
pbtocppobject!
picture!
picturebutton!
picturehyperlink!
picturelistbox!
pipeline!
powerobject!
profilecall!
profileclass!
profileline!
profileroutine!
profiling!
radiobutton!
real!
rectangle!
remoteobject!
resultset!
resultsets!
richtextedit!
roundrectangle!
scriptdefinition!
service!
simpletypedefinition!
singlelineedit!
sslcallback!
sslserviceprovider!
statichyperlink!
statictext!
string!
structure!
systemfunctions!
tab!
time!
timing!
traceactivitynode!
tracebeginend!
traceerror!
traceesql!
tracefile!
tracegarbagecollect!
traceline!
traceobject!
traceroutine!
tracetree!
tracetreeerror!
tracetreeesql!
tracetreegarbagecollect!
tracetreeline!
tracetreenode!
tracetreeobject!
tracetreeroutine!
tracetreeuser!
traceuser!
transaction!
transactionserver!
treeview!
treeviewitem!
typedefinition!
unsignedinteger!
unsignedlong!
userobject!
variablecardinalitydefinition!
variabledefinition!
vprogressbar!
vscrollbar!
vtrackbar!
window!
windowobject!
adoresultset!
any!
application!
arraybounds!
blob!
boolean!
character!
checkbox!
classdefinition!
classdefinitionobject!
commandbutton!
connection!
connectioninfo!
connectobject!
contextinformation!
contextkeyword!
corbacurrent!
corbaobject!
corbaunion!
cplusplus!
datastore!
datawindow!
datawindowchild!
date!
datetime!
decimal!
double!
dragobject!
drawobject!
dropdownlistbox!
dropdownpicturelistbox!
dwobject!
dynamicdescriptionarea!
dynamicstagingarea!
editmask!
enumerationdefinition!
enumerationitemdefinition!
environment!
error!
errorlogging!
extobject!
functionobject!
graph!
graphicobject!
graxis!
grdispattr!
groupbox!
hprogressbar!
hscrollbar!
htrackbar!
inet!
integer!
internetresult!
jaguarorb!
line!
listbox!
listview!
listviewitem!
long!
mailfiledescription!
mailmessage!
mailrecipient!
mailsession!
mdiclient!
menu!
menucascade!
message!
multilineedit!
nonvisualobject!
notype!
objhandle!
olecontrol!
olecustomcontrol!
oleobject!
olestorage!
olestream!
oletxnobject!
omcontrol!
omcustomcontrol!
omembeddedcontrol!
omobject!
omstorage!
omstream!
orb!
oval!
pbtocppobject!
picture!
picturebutton!
picturehyperlink!
picturelistbox!
pipeline!
powerobject!
profilecall!
profileclass!
profileline!
profileroutine!
profiling!
radiobutton!
real!
rectangle!
remoteobject!
resultset!
resultsets!
richtextedit!
roundrectangle!
scriptdefinition!
service!
simpletypedefinition!
singlelineedit!
sslcallback!
sslserviceprovider!
statichyperlink!
statictext!
string!
structure!
systemfunctions!
tab!
time!
timing!
traceactivitynode!
tracebeginend!
traceerror!
traceesql!
tracefile!
tracegarbagecollect!
traceline!
traceobject!
traceroutine!
tracetree!
tracetreeerror!
tracetreeesql!
tracetreegarbagecollect!
tracetreeline!
tracetreenode!
tracetreeobject!
tracetreeroutine!
tracetreeuser!
traceuser!
transaction!
transactionserver!
treeview!
treeviewitem!
typedefinition!
unsignedinteger!
unsignedlong!
userobject!
variablecardinalitydefinition!
variabledefinition!
vprogressbar!
vscrollbar!
vtrackbar!
window!
windowobject!
全部都是系统类型,所以你想判断一个对象是不是datawindow,用typeof就可以了
调用方法也是2种,一个是obj.typeof() , 一个是typeof( obj )