Use resource files in Axapta

Axapta provides a very handy feature to allow developers to ship their solution with Axapta built-in image files. In Application Object Tree, you can find resources node.
Select resources node and right click; select Create from File, specify the file location for the new resource file. After that you can use this resource file in Axapta without specifying an absolute file path in your hard disk.
Then let’s see how to use this kind of files in Axapta.
First, pick up the resource node from AOT;
SysResource::getResourceNode();
Then generate a temporary file for this resource file;
SysResource::saveToTempFile()
Finally specify the temporary file path for controls.
Here comes an example to show how to use a resource file as a background image of  a given form.
{
ResourceNode            resourceNode;
FilePath  imagename;
;
resourceNode = SysResource::getResourceNode(resourcestr(ResourceName));
if (resourceNode)
{
resourceNode. AOTload();
imagename =  SysResource::saveToTempFile(resourceNode);
}
else
{
throw Error(“No file exists.”)
}
element.design().imageName(imagename);
}
Advertisements

One Response to Use resource files in Axapta

  1. mr B says:

    Dear Mr Cool Hake

    mmm i think its nice.
    So i can make AXAPTA display more colourfull.
    By the way i have more simple for just to adding image on the form.
    here’s my code (cropping from msdn.com)

    How to: Add an Image to a Form
    Add an image to a form, such as a company logo.

    Expand the Designs node for the form.

    Right-click the Design node, and then select New Control > Window.

    Open the property sheet for the new control.

    Specify the file name and location in the ImageName property.

    Set the ImageMode property to center the image, put it next to other controls or size the image to fit the default form size.

    You can also specify the image for the control by using the DataSource and DataField properties, or the DataSource and DataMethod properties. For an example, see the tutorial_Form_Windowingrid form.

    For more information on the properties available for a Window control, see Form Control Properties.

    Add a Image by Using Code
    Specify the image for the control by using code to customize how your image is displayed.

    For example, you have created a form with an unbound Window control (a control with no data source). The control is named CompanyLogo, and you want to display a bitmap named Image.bmp.

    Declare a variable for the bitmap in the classDeclaration method on your form.

    Copy Code
    class FormRun extends ObjectRun
    {
    FormWindowControl compLogo;
    ;
    }FormWindowControl is a system class that implements all the properties of a Window control, and also contains methods to manipulate the control.

    Override the init method for the form to add the code that accesses the CompanyLogo control.

    Copy Code
    void init()
    {
    super();
    compLogo = element.design().control(control::CompanyLogo);
    }Write the code to initialize the bitmap display in the run method for the form.

    Copy Code
    void run()
    {
    super();
    compLogo.imageName(‘Image.bmp’);
    }In this example, the bitmap is located in the current directory. The complete path must be specified if the file is located elsewhere.

    To ensure that the image is updated (if you choose to link to another form), insert the code in the linkActive method on the form’s Data Sources node.

    Copy Code
    void linkActive()
    {
    super();
    compLogo.imageName(‘Image.bmp’);
    }

    http://msdn.microsoft.com/en-us/library/aa890890.aspx

    Thanks Sir

Leave a Reply

Fill in your details below or click an icon to log in:

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: