Thanks, Alex.  I actually tried something very similar to this earlier but 
failed.  What I should have done is to try it with my simplified code and then 
I would have realized it was an approach that could work.  The complication is 
that there is much more stuff going on in my production code.  For example, the 
popup menu is defined with a demand-callback function to enable and disable 
menu items, so that something which operates on a selection will be grayed out 
if there is no selection.  This also depends on the table definition.  I'll try 
and figure out how to make that work but, like you said, it's just a matter of 
more indirection.

James


On May 6, 2020, at 9:27 PM, Alex Harsanyi wrote:

> Every problem can be solved by adding another level of indirection (except 
> perhaps having too many  levels of indirection :-) ).  You can put the code 
> below in a separate file:
> 
> (define (make-info-menu-item parent target-table)
>   (new menu-item%
>       (label "info")
>       (parent parent)
>       (callback (lambda (menu-item event)
>                   (message-box "Info"
>                    (~a "You have selected " (length (send target-table 
> get-selected-row-indexes)) " rows")
>                    #f)))))
> 
> And use it like so:
> 
> (require "info-menu-item.rkt")
> (define row-edit-menu (new popup-menu% ))
> (define table3 ...)
> (define info-menu (make-info-menu-item row-edit-menu table3)
> 
> You could also have just one "make-row-edit-menu" function which creates all 
> menu items.
> 
> Alex.
> 
> On Thursday, May 7, 2020 at 7:50:01 AM UTC+8, James Platt wrote:
> I'm working on organizing and documenting some things and I have some code, 
> below, which works but I don't understand why.  Specifically, why don't I get 
> an error about table3 not being defined? 
> 
> This is a very simplified version of what I'm working on.  What I actually 
> want to do is put all the code related to creating a standard table editing 
> menu in a file which I can then include wherever I want that menu.  The full 
> menu will be a lot of code.  Unfortunately I can't seem to get this to work 
> without either getting an error that row-edit-menu is not defined or that 
> table3 is not defined.  In other words, I want to be able to define table3 in 
> one file which requires the file where row-edit-menu is defined but I can't 
> seem to figure out how to get this to work.  It works just fine when all the 
> code is in one file, however. 
> 
> James 
> 
> 
> #lang racket 
> (require racket/gui/base 
>          qresults-list 
>          ) 
> 
> ;set up columns 
> (define (column1 data) (vector-ref data 0)) 
> (define (column2 data) (vector-ref data 1)) 
> 
> (define my-columns 
>   (list 
>    (qcolumn "Column1" column1 column1) 
>    (qcolumn "Column2" 
>             (lambda (row) 
>               ;(displayln row) 
>               ;(displayln (db-row-ref row "Column2" headers 1)) 
>               (if (number? (column2 row)) (number->string (column2 row)) 
> "");This allows a cell to be blank. 
>               ;(number->string (column2 row)) 
>               ) 
>             column2) 
>     
>    ) 
>   ) 
> 
> (define frame3 (new frame% 
>                   [label "myTable 3"] 
>                   [width 800] 
>                   [height 600] 
>                   )) 
> 
> 
> (define row-edit-menu (new popup-menu% )) 
> 
> (define info-menu-item (new menu-item% 
>                               (label "info") 
>                               (parent row-edit-menu) 
>                               (callback (lambda (menu-item event) 
>                                           (message-box "Info" 
>                                                        (~a "You have selected 
> " (length (send table3 get-selected-row-indexes)) " rows") 
>                                                        #f) 
>                                           )) 
>                               )) 
> 
> (define table3 
>        (new (class qresults-list% (init) (super-new) 
>   [parent frame3] 
>   [pref-tag 'preferences-tag] 
>   [selection-type 'multiple] 
>   [right-click-menu row-edit-menu]) 
>   ) 
> 
> (send table3 setup-column-defs my-columns) 
> 
> (send frame3 show #t) 
> 
> (send table3 add-row (vector "R1C1" 10)) 
> (send table3 add-row (vector "R2C1" 11)) 
> (send table3 add-row (vector "R3C1" 12)) 
> (send table3 add-row (vector "R4C1" 13)) 
> 
> 
> 
> -- 
> 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.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/01e04764-42b2-4619-8aff-32fbf4d68269%40googlegroups.com.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/3F35C25B-C546-4297-A5AD-59A6B65D17C2%40biomantica.com.

Reply via email to