Inicio > Desarrollo Escritorio > Eventos en Power Builder

Eventos en Power Builder

Defining user events

* To define a user event for a window, user object, or control:

1. Open the Window painter or User Object painter.

2. Select the window, user object, or control for which you want to declare the user event.

3. Select Declare>User Events from the menu bar.

The Events dialog box displays.

raster

The name and ID of the PowerBuilder and user events defined for the selected object or control display in the Event Name and Event ID listboxes. You cannot modify the predefined PowerBuilder events; they are protected. You can change the event ID for a user event or delete a user event, but you cannot change the name of a user event.

All PowerBuilder event IDs display in the Paste Event ID listbox. The list includes all the events directly supported by Windows plus 75 custom events (pbm_custom01 through pbm_custom75).

4. Enter the name of the event you are declaring in the Event Name box at the end of the list.

5. Double-click the ID of the event you want in the Paste Event ID listbox, as follows:
o If the event corresponds to a Windows message , choose the corresponding PowerBuilder event ID.For more information, see “Understanding user event IDs”.

o If the event does not correspond to a Windows message , choose one of the PowerBuilder custom events (pbm_custom01 through pbm_custom75). For information about custom user events, see “Using custom events”.PowerBuilder assigns the ID to the user event.

6. Click OK.

PowerBuilder closes the Declare Event dialog box and returns you to the painter.

Example

For example, to declare an event for a SingleLineEdit control that is triggered when the user presses a key while in the control, you do the following:

* Select the SingleLineEdit control in the window.

* Select Declare>User Events from the menu bar.

* In the Events dialog box, specify a name (such as CheckKey) and double-click the event ID pbm_keydown, which maps to the appropriate Windows message.

raster

Understanding user event IDs

The PowerBuilder naming convention for user event IDs is similar to the convention Windows uses to name messages. One or more Windows messages maps to each PowerBuilder event ID. For example:

This Windows message Maps to this event ID
wm_keydown pbm_keydown
(button class message) bm_getcheck pbm_bmgetcheck
(notification) bn_clicked pbm_bnclicked

PowerBuilder uses the Windows wm_user message numbers to map custom events (pbm_customnn), as described in “Using custom events” next. PowerBuilder also has its own events; each of these has an ID. For example, the PowerBuilder event DragDrop has the event ID pbm_dragdrop.

For information about Windows messages, see your Microsoft Windows Software Developer’s Kit (SDK) documentation.
Using custom events
What they are for

Custom user events (those that correspond to pbm_customxx event IDs) are not meant to be used with standard controls such as CommandButtons and DropDownListBoxes. Custom user events are meant to be used only with DataWindow controls, windows, and user objects other than standard visual user objects (which behave like the built-in controls they inherit from).

Defining them

In order to define custom user events for the standard controls, you must have some Windows SDK experience and understand the following:

All standard controls respond to standard events in the range 0 to 1023. Most controls also define their own range of custom events beyond 1023 (corresponding to wm_user messages). You need to know which controls have custom events, because these custom events overlap with the PowerBuilder custom events (pbm_customxx). The pbm_custom01 event ID maps to wm_user+0, pbm_custom02 maps to wm_user+1, and so on, through pbm_custom75, which maps to wm_user+74.

You need to make sure that you use a pbm_custom event ID that does not conflict with a custom event defined by Windows for the standard control. Otherwise, you might encounter unexpected behavior in your application.

Using a user event

After defining the user event, you do the following:

Write a script for the user event

If necessary, write code that triggers the event

Writing the script

After declaring the user event, write a script that specifies the processing to occur when the event occurs. User events display in the Select Event listbox in the PowerScript painter below all the built-in events.

raster

Triggering the event

If the user event corresponds to a Windows message (such as pbm_keydown in the example in “Defining user events” ), the event will be triggered automatically when the corresponding action occurs in the application.

If the user event does not correspond to a Windows message (that is, if the event ID is one of the PowerBuilder custom events), you must trigger the event in a script using either the TriggerEvent function or the PostEvent function.

For information about TriggerEvent and PostEvent, see the PowerScript Reference .
Examples of user event scripts

Here are two examples of using user events that map to Windows messages.

Example of custom user events
For an example of using custom user events, see “Using user events” in Chapter 10, “Working with User Objects.”

Example 1

Situation You have several SingleLineEdit controls in a window and want the ENTER key to behave like the TAB key (if users press ENTER , you want them to tab to the next SingleLineEdit).

Solution Define a custom event for each SingleLineEdit. Give the event any name you want, such as CheckKey. Map the event to the event ID pbm_keydown.

raster

Write a script for the user event that tests for the key that was pressed. If ENTER was pressed, set the focus to the SingleLineEdit that you want the user to go to.

For example, in the script for the custom event for sle_1, you could code:

// Script for user event CheckKey,
// which is mapped to pbm_keydown.

IF KeyDown(KeyEnter!) THEN // Go to sle_2 if
sle_2.SetFocus( ) // Enter pressed.
END IF

Similarly, in the script for the custom event for sle_2, you could code:

// Script for user event CheckKey,
// which is mapped to pbm_keydown.

IF KeyDown(KeyEnter!) THEN // Go to sle_3 if
sle_3.SetFocus( ) // Enter pressed.
lb END IF

Example 2

Categorías:Desarrollo Escritorio
  1. Aún no hay comentarios.
  1. No trackbacks yet.

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s

A %d blogueros les gusta esto: