rabbibotton / clog

CLOG - The Common Lisp Omnificent GUI
Other
1.49k stars 102 forks source link

looping for a dynamic table #140

Closed CGenie closed 2 years ago

CGenie commented 2 years ago

I have this pseudo-code:

(loop for (id name some-field) in results-sql
  do (let ((row (create-row table)))
    (create-table-column :content id)
    (set-on-click row (lambda (obj) (my-on-click obj id))))

(defun my-on-click (obj id)
  (create-gui-window obj :title (format nil "Id: ~a" id)))

results-sql is a list of lists, returned by running an SQL statement.

However, it seems that whatever row I click on clog, I get the last id value in the results-sql list (looking at the window title). I analyzed in detail the clog-db-admin.lisp and I can't see any difference between my code. Would you have an idea why is this? I need the loop macro because I want to destructure the row.

rabbibotton commented 2 years ago

Add a (my-id id) in the LET to make it part of the closure around set-on-click. I assume that using "id" from the macro is the issue. Let me know if that worked.

CGenie commented 2 years ago

Ah ok yes, it worked, thank you!