Hi James,

  Like others said, Unit is the proper solution, but to add my 2c, I was
able to avoid this problem altogether by using these two simple tricks :
1) add the controls in the order of their requirement (defining table3
before info-menu-item), then re-ordering the controls before displaying the
window, as follows:

(send frame3 change-children
      (λ (children)
        (list ...
              info-menu-item
              table3
              ...)))

2) to get around the problem of separating gui and logic code, one solution
is to create an englobing 'display-gui' function which takes the callback
func names as parameters. That allows one to move all the callback
functions outside of the GUI, and pipe them through from another module.
For example:

main.rkt:

;;; defs

(define (menu3-callback-proc param1 ...)
   ...)

;;; main

(show-gui  menu3-callback-proc ...)

gui.rkt:
(define (show-gui menu3-callback-proc-name ...)

  gui code...

  )

Let me know if this helps...

Dex

On Thu, May 7, 2020 at 1:50 AM James Platt <j...@biomantica.com> 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/F54B34B7-F04F-4DF7-9236-FD6C4FE3C983%40biomantica.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/CACUENrL0tZx_SYrz1FLWpj4K6FUZOuBmv%2B5L356eN8m9boxb8g%40mail.gmail.com.

Reply via email to