Consultor Eletrônico



Kbase P53874: How to get the procedure handle from the FOCUS widget handle
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   11/14/2003
Status: Unverified

GOAL:

How to get the procedure handle from the FOCUS widget handle ?

FIX:

A window widget has no property to indicate which is the procedure handle wher the window is created. There is CURRENT-WINDOW in THIS-PROCEDURE handle but cannot be used in this case.
We have to assume that the procedure handle is in a range of continuos handles
[ hW - N, hW + N ] where hW is the window handle and N is a random integer.
The following function is trying to locate the procedure handle using the window handle as a starting point:

FUNCTION getProcHandle RETURNS HANDLE ( phFocus AS HANDLE ) :
/*------------------------------------------------------------------------------
Purpose:
Notes:
------------------------------------------------------------------------------*/
DEF VAR hW AS HANDLE.
DEF VAR vh AS HANDLE.

hW = phFocus:FRAME:WINDOW. /* this will be the window handle */
vh = hW.

/* going up until we will get an invalid handle or our procedure handle */
REPEAT :
vh = WIDGET-HANDLE( STRING( INTEGER( STRING( vh:HANDLE ) ) + 1 ) ).
IF VALID-HANDLE( vh )
AND vh:TYPE = "PROCEDURE":U
AND vh:CURRENT-WINDOW = hW
THEN RETURN vh. /* this is my proc handle */
ELSE IF NOT VALID-HANDLE( vh ) THEN LEAVE.
END.

vh = hW.

/* no it is not there so we have to go in the lower range */
REPEAT :
vh = WIDGET-HANDLE( STRING( INTEGER( STRING( vh:HANDLE ) ) - 1 ) ).
IF VALID-HANDLE( vh )
AND vh:TYPE = "PROCEDURE":U
AND vh:CURRENT-WINDOW = hW
THEN RETURN vh. /* this is my proc handle */
ELSE IF NOT VALID-HANDLE( vh ) THEN LEAVE.
END.

/* well if I am here I cannot get the proc handle */
RETURN ?. /* Function return value. */

END FUNCTION.