在 Powerbuilder 的 OpenWithParm 中传递多个参数

Passing multiple parameter in OpenWithParm in Powerbuilder

这是在另一个 pb window 对象中传递单个参数的代码。

dw_header点击事件

long ll_customer
datetime dt_from, dt_to
ll_customer = getitemnumber(1,"customer_id")
dt_from = datetime(date(f_today()),time('00:00:00'))
dt_to = datetime(date(f_today()),time('23:59:59.99'))

openwithparm(w_customer_balance,ll_customer)

w_customer_balance开启活动

long ll_id
datetime dt_from, dt_to
ll_id = message.doubleparm
dw_1.settransobject(sqlca)
dw_1.retrieve(ll_id)

这在传递单个参数时效果很好。 但我想将另一个参数 w/c 是 dt_fromdt_to 传递给客户余额 window。

有人吗?

如果需要传递多个参数,可以使用如下这个方法:

定义结构变量:lstr_declaredstr,其中包含你要传递的参数:

变量类型变量名:

ID Unsignedlong;名称字符;电子邮件字符;首页人物

... ...

调用脚本,使用以下代码:

lstr_declaredstr lstr_parmtotrans
lstr_parmtotrans.id = 1
lstr_paramtotrans.name = "panya"
lstr_paramtotrans.email = "panya@163.net"
lstr_paramtotrans.homepage = "http://panya.163.net"

...

openwithparm (w_wantparm, lstr_paramtotrans)

然后在w_wantparm打开的case中打开window,获取结构信息:

lstr_declaredstr lstr_getparm
integer li_getid
string ls_getname
string ls_getemail
string ls_gethomepage
lstr_getparm = message.powerobjectparm
li_getid = lstr_getparm.id
ls_getname = lstr_getparm.name
ls_geemail = lstr_getparm.email
ls_gethomepage = lstr_getparm.homepage

有关更多示例,请访问此网站:web

您还可以使用您设置的实例变量定义一个非可视对象,然后通过 Openwithparm 方法调用传递。被调用的 window 必须创建 nvo(通常作为实例变量),然后通过 powerobjectparm 参数类型在打开事件中 'received'。

正如 Matt Balent 所建议的那样,与其定义一个专门用于将一些参数传递给 window 的结构,不如创建一个传递给 OpenWithParm() 的专用对象,并且可以在 open()message.powerobjectparm(因为您可以将任何 powerobject 传递给此方法)。

通过扩展,您可以创建一个通用对象类型,它可以接收任意数量的 any 类型的命名参数,您可以在 open() 事件中以类似的方式通过它们的名称获取这些参数作为结构。一种穷人的字典。

这是一个基于一些现有代码的示例:

  • nv_va_arg 对象(类似于 C 的变量参数类型)- 源是从对象 "edit source" 上下文菜单中复制的,要重新创建对象,添加一个新的 "custom class" 对象命名nv_va_args,然后保存 right-click "edit source" 并粘贴以下代码:
      forward
      global type nv_va_args from nonvisualobject
      end type
      end forward

      global type nv_va_args from nonvisualobject autoinstantiate
      end type

      type variables

      private:
      string _is_names[]
      any _ia_items[]

      end variables
      forward prototypes
      public subroutine add_item (string as_name, any aa_val)
      private function integer search (string as_name)
      public subroutine set_item (string as_name, any aa_val)
      public function any get_item (string as_name)
      private subroutine set_item (integer ai_index, string as_name, any aa_val)
      public function integer size ()
      public function string get_name (integer ai_index)
      public function any get_item (integer ai_index)
      end prototypes

      public subroutine add_item (string as_name, any aa_val);
      /* add a new item if not already present */

      int idx

      idx = search(as_name)
      if idx = -1 then
            idx = upperbound(_is_names) + 1
            set_item(idx, as_name, aa_val)
      end if

      end subroutine

      private function integer search (string as_name);
      /* search for an item */

      int i, n
      n = upperbound(_is_names)

      for i = 1 to n
            if _is_names[i] = as_name then return i
      next

      return -1

      end function

      public subroutine set_item (string as_name, any aa_val);
      /* public setter */
      int idx

      idx = search(as_name)
      if idx =-1 then
            idx = upperbound(_is_names) + 1
      end if
      set_item(idx, as_name, aa_val)

      end subroutine

      public function any get_item (string as_name);
      /* get the named item */

      int idx
      any la_val

      idx = search(as_name)
      if idx > 0 then
            la_val = _ia_items[idx]
      end if

      return la_val

      end function

      private subroutine set_item (integer ai_index, string as_name, any aa_val);
      /* internal setter */

      _is_names[ai_index] = as_name
      _ia_items[ai_index] = aa_val

      end subroutine

      public function integer size ();
      /* return the number of elements */
      return upperbound(_is_names)

      end function

      public function string get_name (integer ai_index);
      /* return the name of the nth item */

      string ls_ret = ""
      if ai_index > 0 and ai_index <= upperbound(_is_names) then
            ls_ret = _is_names[ai_index]
      end if

      return ls_ret

      end function

      public function any get_item (integer ai_index);
      /* get the named item */

      any la_val

      if ai_index > 0 and ai_index <= upperbound(_is_names) then
            la_val = _ia_items[ai_index]
      end if

      return la_val

      end function

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

      on nv_va_args.destroy
      TriggerEvent( this, "destructor" )
      call super::destroy
      end on
  • 一个参数填充的例子,你可以使用任何名称和任何类型,将存储在nv_va_args对象的内部any数组中:
        nv_va_args lva_args

        //set some values
        lva_args.add_item("arg_1", 42)
        lva_args.add_item("arg_2", "foo bar")

        //change a value
        lva_args.set_item("arg_2", "foo baz")

        openwithparm(w_test, lva_args)
  • 2 个参数检索示例,放在window 的open() 事件中。请注意,从 message 对象中检索对象必须在事件开始时完成,以免丢失其值(message 对象是一个全局对象,可以很快被覆盖)
        powerobject lpo_arg //do not create it, as it is autoinstanciated
        lpo_arg = message.PowerObjectParm //make immediate copy of the message
        nv_va_args lva_args

        if isvalid(lpo_arg) and not isnull(lpo_arg) then
            lva_args = lpo_arg
        end if

        //example: enumerate all the parameters
        string ls_msg = "", ls_class
        int i
        any la_val
        for i = 1 to lva_args.size()
            ls_msg = ls_msg + lva_args.get_name(i) + ': '
            la_val = lva_args.get_item(i)
            ls_class = classname(la_val)
            if ls_class = "string" or ls_class = "long" then
                ls_msg = ls_msg + string(la_val, "[general]")
            else
                ls_msg = ls_msg + '[' + ls_class + ']'
            end if
            ls_msg = ls_msg + "~r~n"
        next
        messagebox("list of parameters", ls_msg)

        //example: just get a named parameter
        string ls_name = "arg_2"
        la_val = lva_args.get_item(ls_name)
        ls_msg = ls_name + " is " + string(la_val, "[general]")
        messagebox("named parameter", ls_msg)