Open

Opens a window, connects to a scanner, camera, or GPS device, or opens a file and selects its access mode.

For windows Open displays a window and makes all its properties and controls available to scripts.

To

Use

Open an instance of a particular window datatype

Syntax 1 For windows of a known datatype

Allow the application to select the window’s datatype when the script is executed

Syntax 2 For windows of unknown datatype

For BarcodeScanner and BiometricScanner objects Open loads scanner DLLs and connects to scanner firmware.

To

Use

Connect to scanner firmware

Syntax 3 For BarcodeScanner and BiometricScanner objects

For GPS or SerialGPS objects Open opens a communications channel or provides raw data for use by a GPS object.

To

Use

For the GPS base class

Syntax 4 For GPS objects

For the SerialGPS object

Syntax 5 For SerialGPS objects

For other objects Open opens a file and selects its access mode.

To

Use

Open a communications channel or initialize a Camera object with a set of raw data

Syntax 6 For Camera objects

Open a Short Message Service (SMS) session

Syntax 7 For SMSSession objects

Open a file for reading or writing with the FileDirect object

Syntax 8 For FileDirect objects

Open a trace file

Syntax 9 For opening trace files


Syntax 1 For windows of a known datatype

Description

Opens a window object of a known datatype. Open displays the window and makes all its properties and controls available to scripts.

Applies to

Window objects

Syntax

Open ( windowvar {, parent } )

Argument

Description

windowvar

The name of the window you want to display. You can specify a window object defined in the Window painter (which is a window datatype) or a variable of the desired window datatype. Open places a reference to the opened window in windowvar.

parent (child and pop-up windows only) (optional)

The window you want make the parent of the child or pop-up window you are opening. If you open a child or pop-up window and omit parent, PowerBuilder associates the window being opened with the currently active window.

Returns

Integer. Returns 1 if it succeeds and -1 if an error occurs. If any argument’s value is null, Open returns null.

Usage

You must open a window before you can access the properties of the window. If you access the window’s properties before you open it, an execution error will occur.

To reference an open window in scripts, use windowvar.

NoteCalling Open twice If you call Syntax 1 of the Open function twice for the same window, PocketBuilder activates the window twice; it does not open two instances of the window.

To open an array of windows where each window has different datatype, use Syntax 2 of Open.


Parent windows for the opened window

Generally, if you are opening a child or a pop-up window and specify parent, the window identified by parent is the parent of the opened window (windowname or windowvar). When a parent window is closed, all its child and pop-up windows are closed too.

NoteMouse behavior and response windows Controls capture the mouse or stylus action in order to perform certain operations. For instance, CommandButtons capture during mouse clicks, edit controls capture for text selection, and scroll bars capture during scrolling. If a response window is opened while the mouse is captured, unexpected results can occur.

Because a response window grabs focus, you should not open it when focus is changing, such as in a LoseFocus event.

Examples

Example 1

This statement opens an instance of a window named w_employee:

Open(w_employee)

Example 2

The following statements open an instance of a window of the type w_employee:

w_employee w_to_open

Open(w_to_open)

Example 3

The following code opens an instance of a window of the type child named cw_data and makes w_employee the parent:

child cw_data

Open(cw_data, w_employee)

Example 4

The following code opens two windows of type w_emp:

w_emp w_e1, w_e2

Open(w_e1)

Open(w_e2)

See also


Syntax 2 For windows of unknown datatype

Description

Opens a window object when you do not know its datatype until the application is running. Open displays the window and makes all its properties and controls available to scripts.

Applies to

Window objects

Syntax

Open ( windowvar, windowtype {, parent } )

Argument

Description

windowvar

A window variable, usually of datatype window. Open places a reference to the opened window in windowvar.

windowtype

A string whose value is the datatype of the window you want to open. The datatype of windowtype must be the same or a descendant of windowvar.

parent (child and pop-up windows only) (optional)

The window you want to make the parent of the child or pop-up window you are opening. If you open a child or pop-up window and omit parent, PowerBuilder associates the window being opened with the currently active window.

Returns

Integer. Returns 1 if it succeeds and -1 if an error occurs. If any argument’s value is null, Open returns null.

Usage

You must open a window before you can access the properties of the window. If you access the window’s properties before you open it, an execution error will occur.

To reference an open window in scripts, use windowvar.

The window object specified in windowtype must be the same datatype as windowvar (the datatype includes datatypes inherited from it). The datatype of windowvar is usually window, from which all windows are inherited, but it can be any ancestor of windowtype. If it is not the same type, an execution error will occur.

Use this syntax to open an array of windows when each window in the array will have a different datatype. See the last example, in which the window datatypes are stored in one array and are used for the windowtype argument when each window in another array is opened.

NoteConsiderations when specifying a window type When you use Syntax 2, PocketBuilder opens an instance of a window of the datatype specified in windowtype and places a reference to this instance in the variable windowvar.

If windowtype is a descendent window, you can only reference properties, events, functions, or structures that are part of the definition of windowvar. For example, if a user event is declared for windowtype, you cannot reference it.

The object specified in windowtype is not automatically included in your executable application. To include it, you must save it in a PKD file (PocketBuilder dynamic library) that you deliver with your application.

For information about the parent of an opened window, see Syntax 1 For windows of a known datatype.

Examples

Example 5

This example opens a window of the type specified in the string s_w_name and stores the reference to the window in the variable w_to_open. The SELECT statement retrieves data specifying the window type from the database and stores it in s_w_name:

window w_to_open

string s_w_name


SELECT next_window INTO  : s_w_name FROM routing_table

WHERE...  ;


Open(w_to_open, s_w_name)

Example 6

This example opens an array of ten windows of the type specified in the string is_w_emp1 and assigns a title to each window in the array. The string is_w_emp1 is an instance variable whose value is a window type:

integer n

window win_array[10]


FOR n = 1 to 10

		Open(win_array[n], is_w_emp1)

		win_array[n].title = "Window " + string(n)

NEXT

Example 7

The following statements open four windows. The type of each window is stored in the array w_stock_type. The window reference from the Open function is assigned to elements in the array w_stock_win:

window w_stock_win[ ]

string w_stock_type[4]


w_stock_type[1] = "w_stock_wine"

w_stock_type[2] = "w_stock_scotch"

w_stock_type[3] = "w_stock_beer"

w_stock_type[4] = "w_stock_soda"


FOR n = 1 to 4

		Open(w_stock_win[n], w_stock_type[n])

NEXT

See also


Syntax 3 For BarcodeScanner and BiometricScanner objects

Description

Loads DLLs and connects to scanner firmware.

Applies to

BarcodeScanner and BiometricScanner objects

Syntax

Integer scanner.Open ( )

Argument

Description

scanner

The scanner object that you want to open

Returns

Integer. Returns 1 for success or one of the following negative values if an error occurs:

Usage

This is typically the first method to call after creation of a scanner object.

Examples

Example 8

The following example loads scanner DLLs and connects to the scanner device firmware:

li_rtn = l_scanner.Open()

See also


Syntax 4 For GPS objects

Description

Opens an ANSI text file containing NMEA sentences for a GPS object and reads the contents into a buffer.

Applies to

GPS objects

Syntax

GPSname.Open ( { rawdatafile } )

Argument

Description

GPSname

Name of the GPS object.

rawdatafile

A string for an ASCII text file containing raw data in NMEA-0183 format to be used by the GPS object.

Returns

Integer. Returns 1 for success and a negative number for any error. The following is a list of possible error codes and their meanings:

Usage

Use this function to populate the fields of the GPS base object.

The optional rawdatafile argument is used when the data to be loaded resides in an ANSI text file. The entire data file is read into a buffer for use by the GetFix, GetHeading, and GetSatellitesInView routines. Raw data files must be ANSI text.

Examples

Example 9

The following lines create a GPS object, retrieve information about the current position fix, and test the validity of the GPSFix object:

Gps myGPS
GPSFix myFix

Integer rc

String errmsg

MyGPS = CREATE GPS
rc = myGPS.Open("c:\data\ConcordMA.txt")
IF rc = 1 THEN
  rc = MyGPS.GetFix(myFix)

  // process fix data
ELSE

    // process error message with user function 

	errmsg = uf_display_error("Fix Error", rc)

END IF

See also


Syntax 5 For SerialGPS objects

Description

Opens a communications channel for a SerialGPS object and initializes data handlers.

Applies to

SerialGPS objects

Syntax

GPSname.Open ( )

Argument

Description

GPSname

Name of the SerialGPS object.

Returns

Integer. Returns 1 for success and a negative number for any error. The following is a list of possible error codes and their meanings:

Usage

Use this function to open a communications channel for a SerialGPS object and initialize it so that it can be used to obtain GPS information. For the SerialGPS object, you must previously set the SerialPort property and optionally set the ConfigParams proeperty prior to calling this function.

Examples

Example 10

The following lines create a SerialGPS object, retrieve information about the current position fix, and test the validity of the GPSFix object:

SerialGps myGPS
GPSFix myFix

Integer rc

MyGPS = CREATE SerialGPS
rc = myGPS.Open()
IF rc = 1 THEN
  rc = MyGPS.GetFix(myFix)

  IF rc = 1 THEN
    IF myFix.IsFixValid THEN
      // process fix data
    END IF
  ELSE

    // process error message

  END IF

END IF

See also


Syntax 6 For Camera objects

Description

Opens a communications channel for a Camera object and initializes data handlers.

Applies to

Camera objects

Syntax

cameraname.Open ( AppWindow )

Argument

Description

cameraname

Name of the Camera object.

AppWindow

GraphicObject that is required by some camera drivers. Typically you use the name of the main application window.

Returns

Integer. Returns 1 for success, and one of the following negative values if an error occurs:

Usage

Use this function to open a communications channel for a Camera object and initialize it so that it can be used to capture images.

You must set the camera type before you call Open. You must also set either the port or the folder property of the Camera object, depending on the type of camera device you are using. You can set these properties in the Properties view for a Camera object or in a script. The following table describes the properties you need to set for different devices:

Device

CameraType specifier

Port or Folder property (value)

Windows Mobile 5

1

VEO 130S

11

Port (set to "SIO1:")

HP Photosmart

71

Port (set to "SIO1:")

HTC using the IA Camera Wizard

81

Folder (set to the path on the Windows CE device)

Examples

Example 11

The following code creates a Camera object that interfaces with an HP Photosmart camera:

Camera myCamera

myCamera = CREATE Camera 

myCamera.Port= "SIO1:"

myCamera.CameraType=71 
myCamera.Open(w_myphoto_main)
...

See also


Syntax 7 For SMSSession objects

Description

Opens an SMSSession object.

Applies to

SMSSession objects

Syntax

SMSSessionname.Open ( smsproto, msgmodes )

Argument

Description

SMSSessionname

Name of the SMSSession object.

smsproto

An SMSProtocol structure.

msgmodes

A long value indicating whether the SMSSession object is opened in send or receive mode. Values can be:

  • 0 send only (retained to support legacy code)

  • 1 send only

  • 2 receive only

  • 3 send and receive

Returns

Integer. Returns 1 for success and a negative number for any error.

Usage

You can send SMS messages from applications running on any supported Windows CE platform, but you can receive SMS messages only in applications running on Windows Mobile platforms. To receive messages, you also need to deploy a shim DLL that installs with PocketBuilder, and you must register the DLL with the operating system where you deploy it.

For more information about receiving SMS messages in a PocketBuilder application, see the chapter on working with native objects and controls in the Users Guide.

See also


Syntax 8 For FileDirect objects

Description

Use one of these syntaxes to open a file and select its access mode. Use instead of FileOpen to interface directly with the underlying file system when you want to read from or write to a device connected through BlueTooth or other connection tools. The Open function maps to the Windows CE CreateFile command.

Applies to

FileDirect objects

Syntax

Integer instancename.Open ( filename, accessmode, {sharemode, creationdisposition, attributes})

Argument

Description

instancename

Name of the instance of the FileDirect object

filename

A string for the name of the file you want to read from or write to

accessmode

Enumerated value of type stgreadmode. Values can be:

  • stgread!

  • stgreadwrite!

  • stgwrite!

sharemode

Enumerated value of type stgsharemode. Values can be:

  • stgdenynone!

  • stgdenyread!

  • stgdenywrite!

  • stgexclusive!

creationdisposition

Integer indicating what action to take based on whether or not the designated file exists. Values are:

  • 1 Creates a new file if file does not exist, but returns an error if it does exist

  • 2 Creates a new file, overwriting an existing file if necessary

  • 3 Opens an existing file, but returns an error if the file does not exist

  • 4 Opens an existing file or creates a new file if the file does not exist

  • 5 Opens and removes the content of an existing file, but returns an error if the file does not exist

attributes

Integer specifying a handle to a template file that supplies file attributes for the file that you open or create

Returns

Integer. Returns 1 for success and a negative number for any error. Error codes are:

Usage

Use this function to open a file in read or write mode. The FileDirect object supports only the synchronous style of file input or output; further file-related commands cannot be processed until the indicated file is successfully opened or an error in opening the file is caught. The Open function calls the CreateFile method on the device operating system.

Examples

Example 12

The following example calls the FileDirect user object nvo_fileDirect to open a file, read some data, store the data in a blob variable, and close the file:

Integer li_ret, li_AmountRead
Blob lb_data
li_ret = nvo_fileDirect.Open ("MyDoc.txt", stgRead!)
li_ret = nvo_fileDirect.Read (lb_data, 100,     li_amountRead)
li_ret = nvo_fileDirect.Close ( )

See also


Syntax 9 For opening trace files

Description

Opens the specified trace file for reading.

Applies to

TraceFile object

Syntax

instancename.Open ( filename )

Argument

Description

instancename

Instancename of the TraceFile object

filename

A string identifying the name of the trace file you want to read

Returns

ErrorReturn. Returns one of the following values:

Usage

You use this syntax to access the contents of a specified trace file created from a running PocketBuilder application. You can then use the properties and functions provided by the TraceFile object to perform your own analysis of tracing data instead of using the available modeling objects.

Examples

Example 13

This example opens a trace file:

TraceFile ltf_file

String ls_filename


ltf_file = CREATE TraceFile

ltf_file.Open(ls_filename)

...

See also