Remove control

If you need to build a form by Code (we have the case for a customer) and this value is updated by a other form … but your form with the data is not closed and you need to update this value, you need to delete them and rebuild your field. (if you close et re-open the form that’s work … but the customer want not to close the form). You must do by this way.

I take the example in the form tutorial_Form_AddControl and I add a button Delete with method clicked.

class FormRun extends ObjectRun
{
    container   idValue;
}
void clicked() //Button called : “Button”
{
    FormBuildDesign             formBuildDesign = form.design();
    FormBuildGroupControl       formBuildGroupControl;
    FormStringControl c;
    ;
    c = addGroup.addControl(FormControlType::String,'RunTimeControl');
    //MyCode-BEGIN
    idValue += c.id();
    //MyCode-END
    c.label("New control");

    formBuildGroupControl = formBuildDesign.control( addGroup.id() );
}
void clicked()//Button called : “Delete” create by myself
{
    int i;
    ;

    for (i = 1; i <= conLen(idValue); i++)
    {
        element.design().removeControl(conPeek(idValue, i));
    }
}
Advertisements

Save last value in a form

Create a new Class for the form. Example : MyClassForm.

Write : construct() and new() method like this :

server static MyClassForm construct()
{
    return new MyClassForm();
}
void new()
{;
    xSysLastValue::getLast(this);
}

Don’t forget the ClassDeclaration :

class MyClassForm
{
    // Packed
    CustAccount custAccount

    #define.CurrentVersion(1)
    //#define.Version1(1)
    #localmacro.CurrentList
        custAccount
    #endmacro
}

Create pack/unpack method :

public container pack()
{
    return [#CurrentVersion,#CurrentList];
}
public boolean unpack(container packedClass)
{
    Version version = RunBase::getVersion(packedClass);
;
    switch (version)
    {
        case #CurrentVersion:
            [version,#CurrentList] = packedClass;
            break;
        default:
            return false;
    }

    return true;
}

You must add these methods (I don’t have an error at begin because I create my class extends RunBaseBatch, but after I delete this Extends…)

(You can Drag & Drop these method from SalesTableForm, it’s quicker ;-) )

void initParmDefault()
{
}
private identifiername lastValueDesignName()
{
    return '';
}
dataAreaId lastValueDataAreaId()
{
    return curext();
}
// Template method, mustn't be named lastValueElementName
private identifiername lastValueElementName()
{
    return formstr(MyForm);
}
// Template method, mustn't be named lastValueType
private UtilElementType lastValueType()
{
    return UtilElementType::Form;
}
// Template method, mustn't be named lastValueUserId
private userId lastValueUserId()
{
    return curuserid();
}

And, what you must do, it’s in your form (MyForm), modify the classDeclaration method, overwrite the init() and close() method like this :

public class FormRun extends ObjectRun
{
    MyClassForm myClassForm;
}
public void init()
{;
    myClassForm = MyClassForm ::construct(); 

    super();
}
void  close()
{;
    xSysLastValue::saveLast(myClassForm);

    super();
}

I complete for use the variable CustAccount

Create simply a parm method in your class MyClassForm

CustAccount parmCustAccount(CustAccount _custAccount = custAccount)
{
    custAccount = _custAccount;
    return custAccount;
}

And in you form, create an edit() method

edit CustAccount editCustAccount(Boolean _set, CustAccount _custAccount = custAccount)
{
    if( _set)
    {
        myClassForm.parmCustAccount(_custAccount);
    }

    return myClassForm.parmCustAccount();
}