The problem here is that paint-callback is not called synchronously when you 
create a new canvas%, so before the callback code runs, the code following the 
creation of the canvas already attempts to use the drawing context.

Since canvas% implements canvas<%>, could you use the get-dc method of 
canvas<%> to retrieve the drawing context instead of using set! from inside 
paint-callback?

> On Jun 2, 2015, at 11:57, Luke Miles <rashreportl...@gmail.com> wrote:
> 
> 2 questions.
> 
> 
> First, when the the attached code is run, `send` throws an error because `dc`
> still has the value of void.
> 
> Strangely, if I execute the below line in the REPL after the code has run,
> the rectangle is successfully displayed.
> (send dc draw-rectangle 30 20 10 40)
> 
> Why is `dc` still void inside the code but not in the REPL afterwards?
> 
> 
> Second, I have some *bad* code in the attached file:
> (define canvas (void))
> (define dc (void))
> (new canvas% [parent frame]
>             [paint-callback
>               (λ (c d)
>                 (set! canvas c)
>                 (set! dc d))])
> I couldn't find a direct way to get `dc` and `canvas`, and I didn't want to 
> put
> my entire code in the function that paint-callback calls.
> 
> Is there a more straightforward way to get these values?
> 
> Thanks!
> -Luke
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
> <graphics-2.rkt>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to