PageRenderTime 49ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/tcl/class/runme.tcl

#
TCL | 50 lines | 27 code | 14 blank | 9 comment | 0 complexity | df8f7294d88f3c660efe9c27b1259dab MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. # file: runme.tcl
  2. # This file illustrates the high level C++ interface.
  3. # In this case C++ classes work kind of like Tk widgets
  4. catch { load ./example[info sharedlibextension] example}
  5. # ----- Object creation -----
  6. puts "Creating some objects:"
  7. Circle c 10
  8. puts " Created circle [c cget -this]"
  9. Square s 10
  10. puts " Created square [s cget -this]"
  11. # ----- Access a static member -----
  12. puts "\nA total of $Shape_nshapes shapes were created"
  13. # ----- Member data access -----
  14. # Set the location of the object
  15. c configure -x 20 -y 30
  16. s configure -x -10 -y 5
  17. puts "\nHere is their current position:"
  18. puts " Circle = ([c cget -x], [c cget -y])"
  19. puts " Square = ([s cget -x], [s cget -y])"
  20. # ----- Call some methods -----
  21. puts "\nHere are some properties of the shapes:"
  22. foreach o "c s" {
  23. puts " [$o cget -this]"
  24. puts " area = [$o area]"
  25. puts " perimeter = [$o perimeter]"
  26. }
  27. # ----- Delete everything -----
  28. puts "\nGuess I'll clean up now"
  29. # Note: this invokes the virtual destructor
  30. rename c ""
  31. rename s ""
  32. puts "$Shape_nshapes shapes remain"
  33. puts "Goodbye"