Kbase P127162: COM events fire in wrong context with multiple instances of same program
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  04/03/2009 |
|
Status: Unverified
SYMPTOM(s):
COM events fire in wrong context with multiple instances of same program
Events fired in last instance of procedure running
Event search for COM (ActiveX) uses procedure name instead of handle for context
ENABLE-EVENTS OCX method searches using name, not handle
FACT(s) (Environment):
OpenEdge 10.1x
OpenEdge 10.2x
Windows
CAUSE:
Bug# OE00160945
CAUSE:
When two instances of the same procedure are running and used ENABLE-EVENTS to respond to events in an ActiveX control, when that event fires it will fire in the most recently run instance. This is because the internal search algorithm used in Progress/OpenEdge uses the parent procedure name, followed by the event name, to determine the correct context to fire the event in.
For example, procedure 'foo.p' starts an instance of Excel and opens a spreadsheet, then uses ENABLE-EVENTS to respond to events that occur in Excel. When two instances of foo.p are started and events are created in Excel, they are always fired in the most recently run instance.
FIX:
Catch the event and check the context it fired in using handles or something else that is known to your procedure to establish correct context then use PUBLISH/SUBSCRIBE 4GL/ABL to forward the event to the correct context. Below is an example of the problem and the solution. Fill in your own spreadsheets to identify context.
DEFINE INPUT PARAMETER pcWindow AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pcWorkbook AS CHARACTER NO-UNDO.
DEFINE VARIABLE chExcelApplication AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chExcelWorkbook AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE glPublisher AS LOGICAL NO-UNDO.
SUBSCRIBE TO "workbookDeactivate" ANYWHERE.
CREATE 'Excel.Application' chExcelApplication.
chExcelApplication:Visible = TRUE.
chExcelWorkbook = chExcelApplication:Workbooks:Open(pcWorkbook).
chExcelApplication:ENABLE-EVENTS('ExcelEvents').
IF NOT THIS-PROCEDURE:PERSISTENT THEN
WAIT-FOR 'CLOSE' OF THIS-PROCEDURE.
PROCEDURE destroyProc:
RELEASE OBJECT chExcelWorkbook.
RELEASE OBJECT chExcelApplication.
DELETE PROCEDURE THIS-PROCEDURE.
END PROCEDURE.
PROCEDURE ExcelEvents.WorkbookDeactivate:
DEFINE INPUT PARAMETER Wb AS COM-HANDLE.
RUN workbookDeactivate IN THIS-PROCEDURE ( INPUT Wb ).
END PROCEDURE.
PROCEDURE workbookDeactivate:
DEFINE INPUT PARAMETER Wb AS COM-HANDLE NO-UNDO.
IF VALID-HANDLE(Wb) AND (Wb:Name EQ pcWorkbook OR Wb:FullName EQ pcWorkbook) THEN
MESSAGE "Quiting " pcWindow
VIEW-AS ALERT-BOX INFO BUTTONS OK.
ELSE IF NOT glPublisher THEN DO:
glPublisher = TRUE.
PUBLISH "workbookDeactivate" ( INPUT Wb ).
END.
END PROCEDURE.