runme.tcl 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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"