[plt-scheme] MyterX Excel WorkbookBeforeClose ByRef Bool Cancel

From: Ron Stanonik (stanonik at cogsci.ucsd.edu)
Date: Fri May 13 17:47:16 EDT 2005

Does MysterX marshall(?) arguments passed by reference back to the COM object?

For example, the Excel WorkbookBeforeClose event passes a Cancel argument by
reference so that the event handler can prevent closing by setting Cancel
to true.  I tried the obvious in MysterX, but it doesn't prevent closing.

> (require (lib "mysterx.ss" "mysterx"))
> (define excel (cci/progid "Excel.Application"))
> (com-set-property! excel "Visible" #t)
> (define workbook #f)
> (com-register-event-handler excel "NewWorkbook" (lambda(wb)(set! workbook wb)(printf "open ~a~%" wb)))
... Now click on File/New to open a blank workbook ...
> 
open #<com-object>
> (com-register-event-handler excel "WorkbookBeforeClose" (lambda(wb cancel)(printf "closing ~a ~a~%" wb cancel)(set! cancel #t)))
> 
... Now close the open blank workbook ...
closing #<com-object> #&#f

The workbook closes, even though cancel is set to #t.  Oddly, the value
passed in wasn't just #f, but #&#f.

This is for DrScheme 209, downloaded today.

Thanks,

Ron
stanonik at cogsci.ucsd.edu



Posted on the users mailing list.