Consultor Eletrônico



Kbase 18762: One Way To Manage Your COM-HANDLE References
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   8/8/2006
Status: Unverified

GOAL:

One Way To Manage Your COM-HANDLE References

GOAL:

How to manage a COM-HANDLE?

CAUSE:

The method described below simple stores a reference to each COM-HANDLE object you use in your program and then issues a RELEASE OBJECT statement against each
COM-HANDLE when you close your window. Please note that the following will only work well if you properly "save off" each COM-HANDLE reference as it is generated.

The only COM-HANDLE variables which you should not store in this manner are as follows:

1) The UIB/AppBuilder generated COM-HANDLES.

2) The COM-HANDLE returned by the CREATE command if you need to issue some "cleanup" commands to the Automation Object before releasing your last reference to it. An example of this would be using Microsoft Excel where normally you would invoke the Quit() method after all other COM-HANDLE references to Excel
have been released. Doing this forces Excel to terminate.

FIX:

1) Define a temp-table at the beginning of your program which will hold all the references to COM-HANDLE objects you use in your program. Define the temp-table as follows:

DEFINE TEMP-TABLE ttComHandle NO-UNDO
FIELD ComHandleRef AS COM-HANDLE
INDEX PrimaryIndex IS PRIMARY UNIQUE ComHandleRef.
2) Create an internal procedure with the following code in it. You can name the internal procedure whatever you want. You will call this internal procedure immediately after you assign a COM-HANDLE to a variable or when a COM-HANDLE gets passed to you from an event trigger (generated by an OCX or Automation Object).

PROCEDURE StoreComHandleReference:

DEFINE INPUT PARAMETER ComHandleToStore AS COM-HANDLE.

FIND FIRST ttComHandle
WHERE ComHandleRef = ComHandleToStore NO-LOCK NO-ERROR.

IF AVAILABLE(ttComHandle) = FALSE THEN
DO:
CREATE ttComHandle.
ASSIGN ttComHandle.ComHandleRef = ComHandleToStore.
END.

END PROCEDURE.
3) Create an internal procedure with the following code in it. You can name the internal procedure whatever you want. You will call this internal procedure when you close your window. This will cause all COM-HANDLE references to be released properly.

PROCEDURE ReleaseComHandleReferences:

FOR EACH ttComHandle NO-LOCK:
RELEASE OBJECT ttComHandle.ComHandleRef NO-ERROR.
END.

END PROCEDURE.