jeudi 15 septembre 2011

Passing parms between forms

Args class
From Axaptapedia
Jump to: navigation, search
The Args system class is one of the most widely used classes in Axapta. Args is an abbreviation for arguments and an Args object is used to pass information from one object (caller) to another newly created object. Contents [hide]
1 Using Args for object creation
2 Methods and Properties
2.1 caller
2.2 record
2.3 dataset
2.4 lookupField
2.5 lookupValue
2.6 parm
2.7 parmEnum
2.8 parmEnumType
2.9 parmObject
2.10 menuItemName
2.11 menuItemType
3 Examples

[edit] Using Args for object creation
The Args object can also be used to assist in object creation, in conjunction with the ClassFactory. For example, to open a CustTable form, you can use the following code:
Args    args = new Args("CustTable");
 FormRun formRun = ClassFactory.formRunClass(args);
 ;

 formRun.init();
 formRun.run();
 formRun.wait();[edit] Methods and Properties
[edit] caller
public Object caller( [Object _value] )
this method gets or sets the calling object. When creating an args object directly through code, the caller will not be automatically set, so you should set it yourself.
[edit] record
public Common record( [Common _value] )
this method gets or sets a table buffer (record) attached to the Args. A buffer of any table can be attached to an Args object using this method. Be aware when retrieving the buffer that there will be no compile-time check of table id. You should use the dataset method below to check the contents of the buffer.
If the caller and callee are on different tiers, then the applications will automatically copy the buffer to the target tier.
[edit] dataset
public tableId dataset()
this method gets the table Id of a table buffer (record) attached to the Args.
To safely retrieve an attached record from an Args object, use code similar to that shown below. This checks to ensure that there is an attached record, and that it is in fact a SalesTable record, before trying to assign it to the salesTable variable.
if (args.record() && args.dataset() == tableNum(SalesTable))
  salesTable = args.record();
[edit] lookupField
public fieldId lookupField( [fieldId _value] )
see lookupValue
[edit] lookupValue
public str lookupValue( [str _value] )
lookupField and lookupValue are used together. When they are filled with a field Id and value, it indicates that a form opened using the current Args object will automatically select a record based on that criteria.
For example, the following code assumes that a customer with the account code "1000" exists. It will open the CustTable form with customer '1000' selected, but with the other customers still shown. This is the same result visually as is achieved using the Go to Main Table function in Axapta 3.0 and higher.
Args    args = new Args("CustTable");
 FormRun formRun;
 ;

 // Look up customer 1000 when the form opens
 args.lookupField(fieldNum(CustTable, AccountNum));
 args.lookupValue("1000");

 formRun = ClassFactory.formRunClass(args);

 formRun.init();
 formRun.run();
 formRun.wait();Note that this lookup is extremely fast, and should be used in preference to calling .findValue or .findRecord once the form has opened.
[edit] parm
public str parm( [str _value] )
parm is used to pass a string variable to the called object
[edit] parmEnum
public anytype parmEnum( [int _value] )
see parmEnumType
[edit] parmEnumType
public int parmEnumType( [int _value] )
parmEnum and parmEnumType are used together to pass a Base Enum value through to the called object. An example is shown below.
args.parmEnumType(EnumNum(AddressType));
args.parmEnum(AddressType::Delivery);
[edit] parmObject
public Object parmObject( [Object _value] )
parmObject is used to pass a reference to any object to the called object. Be aware of client-server issues if the caller and callee are on different tiers.
[edit] menuItemName
public final str menuItemName( [str _value] )
[edit] menuItemType
public final MenuItemType menuItemType( [MenuItemType _value] )
[edit] Examples

Passing values between forms
From Axaptapedia
Jump to: navigation, search
For passing parameters from one form to another a special class Args is usually used.
Example:
The code of button click event of FormA which calls FormB and passes some parameters to that form.
void clicked()
{
    // Args class is usually used in Axapta for passing parameters between forms
    Args            args;
    FormRun         formRun;
    // Our custom made class for passing complex set of parameters
    FormBParams     formBParams = new FormBParams();
    Array           items = new Array( Types::String );
    int         i;
    ;

    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( strValue.text() );
    // We also can pass enum value to FormB
    args.parmEnum( NoYesEnumValue.selection() );
    args.parmEnumType( EnumNum( NoYes ) );
    // and also can pass a cursor pointing to some record (in our case it is EmplTable )
    args.record( EmplTable );

    // If we want pass more complex set of parameters we can develop our own class
    // just for passing our parameters.
    formBParams.parmSomeDate( someDate.dateValue() );
    formBParams.parmSomeTime( someTime.value() );
    for( i=0; i<ListBox.items(); i++ )
    {
        items.value( i+1,  ListBox.getText( i ) );
    }
    formBParams.parmItems( items );
    // Pass our object to FormB
    args.parmObject( formBParams );

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

    if( formrun.closedOk() )
    {
        answerFromFormB.text( args.parm() );
    }
    super();
}The code of init method of FormB
public void init()
{
    EmplTable       emplTableRecord;
    FormBParams     formBParams;
    Array           items;
    int             i;
    ;
    super();

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

        // get enum parameter
        if( element.args().parmEnumType() == EnumNum( NoYes ) )
        {
            NoYesEnumValue.selection( element.args().parmEnum() );
        }
        // get object parameter
        if( element.args().parmObject() )
        {
            formBParams = element.args().parmObject();
            items       = formBParams.parmItems();
            for( i=1; i<=items.lastIndex(); i++ )
            {
                ListBox.add( items.value(i) );
            }
            someDate.dateValue( formBParams.parmSomeDate() );
            someTime.value( formBParams.parmSomeTime() );
        }
        // get record parameter
        if( element.args().record() && element.args().record().TableId == TableNum( EmplTable ) )
        {
            emplTableRecord =  element.args().record();
            emplName.text( emplTableRecord.Name );
        }
    }
}The code of ok button click event of FromB
void clicked()
{
    super();
    element.args().parm( strAnswer.text() );
    element.closeOk();
}The above code is cut out from a demo which you can download here.


exemple
public void printBOM(int _nodeIdx)
{
    BOMTable            bomTable;
    MenuFunction        menuFunction;
    Args                args = new Args();
    if (!this.canPrintBOM(_nodeIdx))
    {
        return;
    }
    bomTable = node2BOMTable.lookup(_nodeIdx);
    if (    bomTable.CheckBOM
        && !BOMHierarchyCheck::checkBOM(bomTable.bomId,true))
    {
        return;
    }
    startLengthyOperation();
    menuFunction = new MenuFunction(menuitemOutputStr(BOMConsistOfReport), MenuItemType::Output);
    args.parmObject(this);
    args.parm(int2str(_nodeIdx));
    menuFunction.run(args);
}

Aucun commentaire:

Enregistrer un commentaire