Posted to tcl by apw at Sun Sep 16 12:17:01 GMT 2007view raw

  1. Hi George,
  2.  
  3. I have a perhaps not completely satisfying answer for megpkg:
  4.  
  5. ::itcl::type s1 {
  6. option foo
  7. option key -configuremethod callbackKey -validatemethod valKey
  8. option anotherkey
  9. constructor {args} {
  10. configure {*}$args
  11. }
  12. method valKey {option value} {
  13. if {$value eq "bob"] {
  14. return 1
  15. }
  16. if {$options(key) ne ""} {
  17. error "you changed -text"
  18. }
  19. return 0
  20. }
  21. method callbackKey {option value} {
  22. set options($key) $value
  23. }}
  24.  
  25. set s [s1 #auto -foo bar -key value -anotherkey value]
  26.  
  27. puts [$s cget -key]
  28. $s configure -key Hello
  29. # produces the error above
  30. $s configure -key bob
  31. # sets key to bob
  32.  
  33. you don't need locking as only defined options are allowed
  34.  
  35. for setting and getting the options you can use configure and cget
  36.