Using PocketBuilder resource files

Instead of distributing resources separately, you can create a PKR file that lists all dynamically assigned resources. A PKR file is a Unicode or ANSI text file in which you list resource names (such as BMP, ICO, and GIF files) and DataWindow objects. To create a PKR file, use a text editor. List the name of each resource, one resource on each line, then save the list as a file with the extension PKR. Here are the contents of a sample PKR file:

ct_graph.ico
document.ico
codes.ico
button.bmp
next1.bmp
prior1.bmp

PocketBuilder compiles the listed resources into the executable file or a dynamic library file, so the resources are available directly at runtime.

NoteUsing DataWindow objects If the objects in one PKL reference DataWindow objects (either statically or dynamically) that are in a different PKL, you must either specify a PocketBuilder resource file that includes the DataWindow objects, or define the library that includes them as a PKD that you distribute with your application. Unlike image files, you cannot distribute the objects separately.

When a resource such as a bitmap is referenced at runtime, PocketBuilder first looks in the executable file for it. Failing that, it looks in the PKD files that are defined for the application. Failing that, in test mode only (that is, on the desktop), it looks in directories in the search path for the file.

Using a resource file

StepsTo use a PocketBuilder resource file:

  1. Using a text editor, create a text file that lists all resource files referenced dynamically in your application.

    You must include the path of the file if it is not in the current directory. See “Naming resources”.

    When creating a resource file for a dynamic library, list all resources used by the dynamic library, not just those assigned dynamically in a script.

  2. Specify the resource files in the Project painter. The executable file can have a resource file attached to it, as can each of the dynamic libraries.

    When PocketBuilder builds the project, it includes all resources specified in the PKR file in the executable file or dynamic library. You do not have to distribute your dynamically assigned resources separately; they are in the application.

Naming resources

If the resource file is in the current directory, you can simply list the file, such as:

FROWN.BMP

If the resource file is in a different directory, include the path to the file, such as:

C:\BITMAPS\FROWN.BMP

If the reference in a script uses a path, you must specify the same path in the PKR file. If the resource file is not qualified with a path in the script, it must not be qualified in the PKR file.

NotePaths in PKR files and scripts must match exactly The file name specified in the PKR file must exactly match the way the resource is referenced in scripts.

For example, if the script reads:

p_logo.PictureName = "FROWN.BMP"

then the PKR file must read:

FROWN.BMP

If the PKR file says something like C:\MYAPP\FROWN.BMP and the script does not specify the path, PocketBuilder cannot find the resource at runtime.

PocketBuilder does a simple string comparison at runtime. In the preceding example, when PocketBuilder executes the script, it looks for the object identified by the string “FROWN.BMP” in the executable file. It cannot find it, because the resource is identified in the executable file by the string “C:\MYAPP\FROWN.BMP”. In this case, the picture does not display at runtime; the control is empty in the window.

NoteResources not deployed to a path on the device The resources that you include in a PKR are built into the executable or PKD; they are not deployed as separate files to the device or emulator. The fact that there is no C: drive on the device does not matter. “C:\MYAPP\FROWN.BMP” is simply a string that identifies the resource in the executable or PKD.

Including DataWindow objects in a PKR file

To include a DataWindow object in the list, enter the name of the library (with the extension PKL) followed by the DataWindow object name enclosed in parentheses. For example, here is a sample PKR file that includes DataWindow objects as well as other resources:

button.bmp
next1.bmp
prior1.bmp
logo.gif
dws.pkl(d_cust)
dws.pkl(d_custlist)

If the DataWindow library is not in the directory that is current when the executable is built, fully qualify the reference in the PKR file. For example: c:\myapp\sales.PKl(d_emplist).