动态创建用户对象对象的方法

来源:互联网 发布:淘宝卖家怎么发微淘 编辑:程序博客网 时间:2024/05/01 18:02

分类:

分析代码:
string ls_objectname
IF NOT IsValid(inv_NewStyle) or isNull(inv_NewStyle) THEN
 if ai_style= FlatStyle then
   ls_objectname = "n_cst_buttonsrv_NewStyle_flat"
 elseif ai_style= XPStyle then
  ls_objectname = "n_cst_buttonsrv_NewStyle_XP"
 elseif ai_style= GradientStyle then
  ls_objectname = "n_cst_buttonsrv_NewStyle_Gradient"
 end if
 inv_NewStyle = CREATE USING ls_objectname
 inv_NewStyle.of_SetRequestor(THIS)
else
 of_removenewstyle()
 of_setnewstyle(ai_style)
END IF
 
ls_objectname
 是一个字符串用来记录被创建对象的上一级的用户对象名称。
 
n_cst_buttonsrv_NewStyle_flat
n_cst_buttonsrv_NewStyle_XP
n_cst_buttonsrv_NewStyle_Gradient
三个是当前系统中已经存在的用户对象
 
private:
n_cst_buttonsrv_newstyle inv_NewStyle
是一个私有实例变量,注意该私有变量是
n_cst_buttonsrv_NewStyle_flat
n_cst_buttonsrv_NewStyle_XP
n_cst_buttonsrv_NewStyle_Gradient
的祖先类,也就是说这三个用户对象是由,祖先类n_cst_buttonsrv_newstyle派生而来的。
 
inv_NewStyle = CREATE USING ls_objectname
根据ls_objectname创建类的实例。
就是说inv_NewStyle可能是
n_cst_buttonsrv_NewStyle_flat
n_cst_buttonsrv_NewStyle_XP
n_cst_buttonsrv_NewStyle_Gradient
三者之一。
 
 
总结:
动态创建类的实例变量的时候 ,改实例变量必须为 using 后字符串类的祖先类。
 
优点:
没有必要写三次 Create了,和Destroy啦。
0 0
原创粉丝点击