Call a method on caller form

Sometimes you need to call a function on the calling form. You can use the following x++ code to achieve this.

1)Form

/*
element.args().caller().<Method on caller form>();

这个语句的意思代表打开当前这个对象的父对象的句柄。
那么可以用if(element.args().caller())来检测当前对象是否是被其他对象调用而打开的。
而且可以通过这个语句获得的句柄来调用父对象中定义的方法。

For example

element.args().caller().GS_Refresh();


The problem with the code above is that you don't get any compilation errors if the method doesn't exist. To handle this problem, you can use the following code.

*/

if (formHasMethod(element.args().caller(), identifierStr(GS_Refresh)))
{
    element.args().caller().GS_Refresh();
}

2)Class

//Class1中有两个方法:
void hello()
{
      print "hello world";
}
static void main(Args _args)
{
      Class1 c1 = new Class1();
      ;
      _args = new Args();
      _args.object(c1);
      _args.caller(c1);
      Class2::Main(_args);
}
//在Class2中编写如下代码测试:
static void main(Args _args)
{
      _args.caller().hello();//这里在敲完caller()方法后的点后的方法列表中不会显示出hello这个方法,需要你手动的敲进去。
}

/*
我们可以从以上示例可以看出,caller需要在父对象中方法中用args.caller(...)来指定。
而这里,有一个特例那就是用menuitem button封装来打开的对象中的args.caller()对象缺省为那个承载menuitem button的formRun或者reportRun等对象。

*/


 

 

 

posted @ 2010-12-29 15:12  Fandy Xie  Views(290)  Comments(0Edit  收藏  举报