Home > X++ stuffs > Generation of CodePage using X++

Generation of CodePage using X++


Case Study: In this demo scenario, we are going to build Windows Code page using X++ class.
For this project, I have build a generation class which basically returns the list of available codePage.

private void buildCodePage()
{
    System.Text.EncodingInfo[]    encodingInfoArray;
    System.Text.EncodingInfo      encodingObject;

    RecordInsertList              recordInsertList =  
                                  new RecordInsertList(tableNum(CodePageTable));
    System.Exception              ex;
    InteropPermission             permission = 
                                  new InteropPermission(InteropKind::ClrInterop);
    ;

    // Clear always the codePage data is available
    delete_from codePage;

    try
    {
        permission.assert();
        encodingInfoArray = System.Text.Encoding::GetEncodings();

        // BP Deviation Documented.
        for (i = 0; i <= 
                    CLRInterop::getAnyTypeForObject(
                    encodingInfoArray.get_Length()) - 1; 
            i++ )
        {
            encodingObject = encodingInfoArray.GetValue(i);

            codePage.CodePage    = System.Convert::ToString(
                                   encodingObject.get_CodePage());
            codePage.DisplayName = System.Convert::ToString(
                                   encodingObject.get_DisplayName());

            recordInsertList.add(codePage);
        }

        ttsbegin;
                recordInsertList.insertDatabase();
        ttsCommit;

        CodeAccessPermission::revertAssert();
    }
    catch (Exception::CLRError)
    {
        ex = ClrInterop::getLastException();

        if (ex != null)
        {
            ex = ex.get_InnerException();
            if (ex != null)
            {
                error(ex.ToString());
            }
        }
    }
}


Once this code is executed the runtime formRun displays the required output as shown below.

This form displays the codePage

AX2012 DLink: SharedProject_CodePage happy AX2012 🙂

AX20009 DLink: SharedProject_CodePage happy AX2009 🙂

Advertisements
Categories: X++ stuffs
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: