[plt-scheme] Re: MyterX Excel WorkbookBeforeClose ByRef Bool Cancel
On Fri, 13 May 2005, Ron Stanonik wrote:
> 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.
Found it. Replace (set! cancel #t) with (set-box! cancel #t).
Ron