Consultor Eletrônico



Kbase P6864: 4GL: How to know if an instance of an OCX is running?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   3/7/2003
Status: Unverified

GOAL:

4GL: How to know if an instance of an OCX is running?

FACT(s) (Environment):

Progress 9.X

FIX:

Rely on a 4GL SUBSCRIBE + PUBLISH mechanism in each procedure that uses the OCX as illustrated bellow:

1) Define the following variable in the definition block:
DEFINE VARIABLE IsTheOcxRunningFlag AS LOGICAL NO-UNDO.

2) Subscribe to a 'IsTheOcxRunning' event when initializing the ActiveX (such as in Internal Procedure initialize-controls or adm2 initializeObject):
SUBSCRIBE TO "IsTheOcxRunning" ANYWHERE.

3) Make the following Internal Procedure:PROCEDURE IsTheOcxRunning:
/* Will happen when 'IsTheOcxRunning' published by itself */
IF SOURCE-PROCEDURE = THIS-PROCEDURE THEN RETURN.

/* Now we know that 'IsTheOcxRunning' was published by an other procedure */
DYNAMIC-FUNCTION("setIsTheOcxRunning" IN SOURCE-PROCEDURE, INPUT YES).
END PROCEDURE.

4) Collect the answer of the procedure(s) with the following function:FUNCTION setIsTheOcxRunning RETURNS LOGICAL
(INPUT inFlag AS LOGICAL) :
IsTheOcxRunningFlag = inFlag.
RETURN YES. /*Actually, we do not care about this returned value
=> Similar to a method that returns true when the process
was successful */
END FUNCTION.

5) Read the answer of the procedure(s) with the following function:FUNCTION getIsTheOcxRunning RETURNS LOGICAL
( /* parameter-definitions */ ) :
RETURN IsTheOcxRunningFlag. /* Function return value. */
END FUNCTION.

6) Example of use:ON CLOSE OF THIS-PROCEDURE DO:
setIsTheOcxRunning(NO). /*not necessary if we do the job only once before
closing the procedure*/
PUBLISH "IsTheOcxRunning".

IF getIsTheOcxRunning() THEN
MESSAGE "The OCX is running somewhere else, don't release it"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
ELSE MESSAGE "No, the OCX was not used somewhere else" SKIP
"So we can release it"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
RUN disable_UI.
END.