如何在Axapta中的两种形式之间传递参数? [英] How to pass a parameter between two forms in Axapta?

查看:41
本文介绍了如何在Axapta中的两种形式之间传递参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在axapta中的表单之间传递单个参数?我想通过表单A中的单击按钮事件运行表单B并传递...例如客户ID? 如何以目标形式(例如 init 方法)读取它? 谢谢

How can i pass a single parameter between a form in axapta ? I want to run a Form B from a clicked button event in a Form A and pass... for example the customer id ? How can i read it in the destination form, maybe in the init method ? Thanks

推荐答案

1方法

最简单的方法是传递当前记录.如果CustTable在当前Form数据源中,只需将按钮控件的Example的DataSource值更改为CustTable.然后以目标形式的init方法:

1 Method

The easiest way is to pass current record. Just change button control's DataSource value for Example to CustTable if CustTable is in current Form data sources. Then in destination form init method:

public void init()
{
    CustTable cTable;
    ;
    super();

    // Check for passed arguments
    if( element.args() )
    {
        // get record parameter
        if( element.args().record() && element.args().record().TableId == TableNum( CustTable ) )
        {
            cTable =  element.args().record();            
        }
    }
}

2方法

如果您仍需要传递一个值.parm()(或更复杂的对象.parmObject()),则可以通过覆盖源表单的按钮控件单击方法来做到这一点:

2 Method

If you still need pass exactly one value .parm() (or more complex object .parmObject() ) you can do this by overiding source form's button control clicked method:

void clicked()
{
    // Args class is usually used in Axapta for passing parameters between forms
    Args            args;
    FormRun         formRun;
    ;

    args = new args();

    // Our values which we want to pass to FormB
    // If we want pass just simple string we can use 'parm' method of 'Args' class
    args.parm( "anyStringValue" );

    // Run FormB
    args.name( formstr( FormB ) );
    formRun = classFactory.formRunClass( Args );
    formRun.init();
    formrun.run();
    formrun.wait();

    super();
}

然后以目标形式init:

Then in destination form init:

public void init()
{
    str             anyStringValueFromCaller;
    ;
    super();

    // Check for passed arguments
    if( element.args() )
    {
        // get string parameter
        anyStringValueFromCaller = element.args().parm();

    }
}

我绝对应该只使用第一种方法,并且只有在特殊情况下才使用带有覆盖按钮单击方法的#2方法,因为这是在表单之间传递值的默认模式之一. 在 AxaptaPedia.com中可以找到更复杂的示例

I should definitely would use only the first method and only in special circumstances would go with #2 method with overriding button click method because this is one of default pattern for passing values between forms. More complex example is available at AxaptaPedia.com Passing values between forms

这篇关于如何在Axapta中的两种形式之间传递参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆