Tabular IQ

Overview

The Extension class provides information about and access to extension packages. Many times bitmap or text resources need to be loaded from the extension package to be displayed in the user interface of the extension. This class facilitates this functionality.

Methods

Extension.getBinaryResource
Loads a binary resource from an extension
Extension.getBitmapResource
Loads a bitmap resource from an extension
Extension.getTextResource
Loads a text resource from an extension
Extension.isContextPackage
Determines if the program is running from a package

Example

// assuming an extension file with a picture called "mountains.jpg"
// and a script file called "main.js", the following should demonstrate
// loading bitmap and text resources

class MyForm extends Form {
    // the bitmap is passed in rather than loaded here, because its size
    // determines the arguments to super() -- and a derived constructor
    // cannot bail out before calling super()
    constructor(bmp) {
        const width = bmp.getWidth();
        const height = bmp.getHeight();

        super("Startup Picture", 1, 1, width - 20, height);
        this.center();

        const picture = new PictureBox(0, 0, width, height - 70);
        picture.setImage(bmp);
        this.add(picture);

        const button = new Button("Show Source", 5, height - 65, 80, 24);
        button.click.connect(this, this.onShowSource);
        this.add(button);
    }

    onShowSource() {
        alert(Extension.getTextResource("main.js"));
    }
}


const bmp = Extension.getBitmapResource("mountains.jpg");
if (!bmp) {
    alert("mountains.jpg is missing from the extension.");
} else {
    const f = new MyForm(bmp);
    f.show();

    Application.run();
}

Extension.getBinaryResource

static function Extension.getBinaryResource(path : String) : MemoryBuffer

Arguments

path
The path to the desired resource either in the extension file or extension directory

Returns

A valid string upon success, null otherwise

Description

Loads a binary resource from an extension package. If the extension is packaged up into a kxt/zip file, the resource is loaded from that archive. If the extension is not packaged up, but is rather one or more non-packaged files in a directory, the resource is loaded from that directory.

Extension.getBitmapResource

static function Extension.getBitmapResource(path : String) : Bitmap

Arguments

path
The path to the desired resource either in the extension file or extension directory

Returns

A valid bitmap object upon success, null otherwise

Description

Loads a bitmap resource from an extension package. If the extension is packaged up into a kxt/zip file, the resource is loaded from that archive. If the extension is not packaged up, but is rather one or more non-packaged files in a directory, the resource is loaded from that directory.

Extension.getTextResource

static function Extension.getTextResource(path : String) : String

Arguments

path
The path to the desired resource either in the extension file or extension directory

Returns

A valid string upon success, null otherwise

Description

Loads a text resource from an extension package. If the extension is packaged up into a kxt/zip file, the resource is loaded from that archive. If the extension is not packaged up, but is rather one or more non-packaged files in a directory, the resource is loaded from that directory.

Extension.isContextPackage

static function Extension.isContextPackage() : Boolean

Returns

True if the program is running from an extension package, false otherwise

Description

Calling this method allows the caller to determine if the program running is running in from a context of an extension package.