`
Ben.Sin
  • 浏览: 229755 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

提取DataWindow的参数

    博客分类:
  • PB
 
阅读更多

这里说的DataWindow是指dataobject的那个,而不是DataWindow Control

DataWindow可以有几个参数,但是PB并没有提供专门的函数去取得这些参数,DW Syntax也没有指出用那些关系可以去除这些参数信息。但是这些信息还是可以直接取得

dw_control.object.dataWindow.table.arguments

取出来的是一个字符串,参数之间通过~n连接,参数名和参数类型之间通过~t连接

比如有参数arg1/String和arg2/Number,我们用上述语句得到的结果就会是

"arg1~tString~narg2~tNumber"

所以这里取出来还需要做一些出来才能利用这些信息

// 定义一个custom user object去记录参数信息

(PB代码)

$PBExportHeader$nvo_dw_args.sru
forward
global type nvo_dw_args from nonvisualobject
end type
end forward

global type nvo_dw_args from nonvisualobject autoinstantiate
end type

type variables
string argName
string argType
end variables

on nvo_dw_args.create
call super::create
TriggerEvent( this, "constructor" )
end on

on nvo_dw_args.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on

event constructor;/**
 * This object use to store the argument info of datawindow
 * argName store argument's name
 * argType store argument's data type
 */
end event

// 读取和分析参数并返回参数信息

(PB代码)

$PBExportHeader$n_cst_dw_util2.sru
forward
global type n_cst_dw_util2 from nonvisualobject
end type
end forward

global type n_cst_dw_util2 from nonvisualobject
end type

global n_cst_dw_util2 n_cst_dw_util2

type variables
DataWindow		idw
end variables

forward prototypes
public function integer of_getarguments (ref nvo_dw_args args[])
end prototypes

public function integer of_getarguments (ref nvo_dw_args args[]);/**
 * get the registe datawindow arguments. 
 * the arguments will be store into nvo_dw_args array args[]
 * @param ref args[]- nvo_dw_args
 * @return integer
 * - return the arguments count if successful
 * - return 0 if no arguments
 * - return -1 if invalid idw or error
 * @author Ben
 * @history
 * 1. created	21-Apr-2008		Ben
 */

string ls_argStr
string ls_tmpArg
integer li_pos, li_posTab, li_index

if not isValid(idw) then return -1	

ls_argStr = idw.object.dataWindow.table.arguments

if isNull(ls_argStr) or ls_argStr = "" then return 0

do
	li_pos = pos(ls_argStr, '~n')	

	if li_pos > 0 then
		ls_tmpArg = left(ls_argStr, li_pos - 1)
		ls_argStr = right(ls_argStr, len(ls_argStr) - li_pos)
	else
		ls_tmpArg = ls_argStr
	end if

	if not isNull(ls_tmpArg) and ls_tmpArg <> "" then
		li_posTab = pos(ls_tmpArg, '~t')
		
		if li_posTab > 0 then
			li_index = upperBound(args) + 1
			args[li_index].argName = left(ls_tmpArg, li_posTab - 1)
			args[li_index].argType = right(ls_tmpArg, len(ls_tmpArg) - li_posTab)
		end if
	end if
loop while li_pos > 0

return 1
end function

on n_cst_dw_util2.create
call super::create
TriggerEvent( this, "constructor" )
end on

on n_cst_dw_util2.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on

返回的nvo_dw_args数组包含了参数名和参数类型,这样比较方便使用.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics