Warm tip: This article is reproduced from stackoverflow.com, please click
axapta microsoft-dynamics x++

Using a variable created in other class extension

发布于 2020-04-23 10:59:23

I need to pass a boolean variable from one class to another. How can I archive this ? I have 2 classes, one create and set the boolean value and the other class need to get this value. It's all because I need to run code on true value for a different form. How should I declare new classB in here ? It dont let me use my class ProdParmReportFinishedWG_Extension.

[ExtensionOf(formStr(ProdParmReportFinished))]
final class ProdParmReportFinishedWG_Extension
{

public boolean TestB;


public boolean parmIsTest(boolean _test = TestB)
{
    TestB = _test;
    return TestB;
}

public void run()
{
    next run();


    if(TestB)
    {
        Ok.enabled(false);
        Info("@SRM:SRM00049");
    }
    else
    {
        Info('im false');
    }
 }

 }


[ExtensionOf(formdatasourcestr(ProdTableListPage, ProdTable))]
final class ProdParmReportFinishedActiveWG_Extension
{
public boolean Test;

    public int active()
{
    int ret;
    next Active();
    ProdTable tableBuffer = this.cursor();
    ProdTable prodtable;
    ProdParmReportFinishedWG_Extension ClassB = new ProdParmReportFinishedWG_Extension();


    ;

    if(tableBuffer.ProdId == tableBuffer.CollectRefProdId
             && tableBuffer.ProdStatus != ProdStatus::ReportedFinished)
    {
               select firstonly RecId,ProdId from ProdTable where
                  ProdTable.CollectRefProdId == tableBuffer.ProdId
                  && ProdTable.Prodstatus != ProdStatus::ReportedFinished
                  && tableBuffer.RecId != prodtable.RecId;
                  {
                      Test = true;
            ClassB.parmIsTest(Test);
            ClassB.Run();

                  }
            }
        else
        {
            Global::info(strFmt("%1 , %2, %3, %4",
            tableBuffer.prodid, tableBuffer.CollectRefProdId, tableBuffer.InventRefType, tableBuffer.ProdStatus));
        }

    return ret;
}

}
Questioner
Radosław Mierzejewski
Viewed
22
Jonathan Bravetti 2020-02-07 23:14

There are several ways, you can try something like this:

Example, in class A define and set boolean variable, in class B pass the boolean variable and use your logic.

Code example:

Class A

class A
{
    boolean Test;
}

private void Run()
{
    B ClassB = new B();

    ;

    //Your logic to set boolean variable
    Test = true;
    ClassB.parmIsTest(Test);
    ClassB.Run();
}

Class B

class B
{
    boolean TestB;
}

public boolean parmIsTest(boolean _test = TestB)
{
    TestB = _test;
    return TestB;
}

public void Run()
{
    //Do your logic
    if(TestB)
    {
        //Your code...
    }
    else
    {
        //Your code...
    }
    //Do your logic END
}