home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Environments / Prograph Classic 2.6.1 / Prograph Tutorial Manual / Prograph Tutorial / Prograph Tutorial.rsrc / TEXT_139.txt < prev    next >
Encoding:
Text File  |  1995-10-16  |  12.8 KB  |  240 lines

  1. t    Creating Methods during Runtime
  2.  
  3. *679*The Prograph development environment and your application run concurrently. You can interrupt your application at any time to add or edit methods, create new classes, and create or edit menus, windows, and window items‚Äîjust about anything you want to do. 
  4.  
  5. Most object-oriented languages require you to go through elaborate procedures to perform class and instance alterations. You have to ‚Äúkill‚Äù all instances of a class before changing a class, which is then recompiled. You have to destroy an instance, alter the class definition, and then recreate the instance to have that instance take on new attributes, and so on. Prograph does not slow you down with such distractions. You keep your mind on your programming objectives, not on object and class management. The best way to appreciate the dynamic relationship between Prograph‚Äôs editors and your application is to see it in action.
  6.  
  7. u The blinking insertion bar in the Edit field of the Folks Database window indicates your application is ready for input. Type Johnny.
  8.  
  9. u Press the Add button. A dialog pops up informing you that the Add method in class Person does not exist. Press Return to continue. An execution window for the new Add method opens.
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25. ___________________________________________________________
  26. NOTE: Prograph shows you that it created an empty method with the name Add in class Person. You specified this method in the*168* Click Method field of the Button editor when you created the Add button. Prograph has done some of the work for you: it created a new method with the specified name in the specified class. If you were to open the Methods window of class Person, you would see the Add method icon along with the methods you wrote earlier.
  27.  
  28. Recall the layered-rings graphic at the beginning of this chapter describing the Prograph Development System. The *51*Application Builder manages menus, windows, and events. Windows and menus are the physical manifestations of a Macintosh user interface. The unseen but critically important third component of a user interface is specification of what these windows and menus do when a user interacts with them using the mouse and keyboard. In Macintosh terms, *555*these interactions are called events.
  29.  
  30. Most Macintosh languages require you to manage the Macintosh *552* event loop, a portion of an application that repetitively looks for and reacts to user events. Prograph manages the event loop automatically, thereby greatly simplifying application development. You concentrate on what your program does when these events happen. You don‚Äôt get bogged down just trying to figure out when events happen. Anthropomorphically speaking, Prograph is saying, ‚ÄúI have detected a button-press event. You indicated that when this button was clicked I should execute*682* the Add method in the Person class. This method does not exist, so I have created a skeletal one for you. If you *491*inspect the three roots of the input bar, you see that the Window object in which this event took place is arriving on the left root, and the Button object pressed is arriving on the middle root. And if you are a low-level Macintosh programmer interested in the contents of the actual event record for this mouse click, I have provided it on the right root.‚ÄùBy opening an editable*143*  case window on the Add method, you can immediately tell Prograph what to do whenever its internal event-loop processing detects a user pressing the Add button in the Folks Database window*1181*.
  31. -----------------------------------------------------------
  32.  
  33. The roots of the input bar of the newly created Add method come labelled with comments indicating the type of data expected there.
  34.  
  35. u To actually inspect the objects arriving on those roots, press Return.
  36.  
  37. *553*The execution highlight moves from the input bar to the output bar. The grayed-out roots of the input bar change into unfilled circles, indicating inspectable data values have passed into them.
  38.  
  39. u Double-click the left root to open a Value window.
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56. The scrolling-list pane in the upper left corner of the Value *1143*window indicates that a Window object has arrived on the root. The larger right-side scrolling list indicates the values*94* of the attributes of this particular instance of Window. The first item, name, shows that the Window with the click event was the Folks Database window.
  57.  
  58. u Drag the scroll box of the attribute-list pane to the bottom of its scroll area to reveal the last item in the attribute list. This attribute is item list, which is the list of Window Item instances that are part of the Folks Database window.
  59.  
  60. u To inspect the contents of item list, double-click the item list triangle-shaped attribute icon to open a second layer of Value window.
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79. Notice, item list contains two Window Item *1061**1174*objects, the Edit Text and Button objects that you created. Before you can assign a name to the new Person object to be created, you need to extract the text attribute-string value from the Edit Text object. *720*
  80.  
  81. u Your target data value is the name typed into the Edit Text item of your application window. To inspect the Edit Text data value, double-click on the attribute icon of the Edit Text object in the attribute pane of the item list value window.
  82.  
  83. u Drag the scroll box of the attribute list pane almost to the bottom of its scroll area. Find the text attribute icon. Above the icon you see text has the value "Johnny." This is the data you want to pass to the birth method.
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97. ___________________________________________________________
  98. NOTE: Making the Add button work involves two simple steps. First, get the text attribute value from the Edit Text item in the item list of the Folks Database window. Then pass this string to the birth method in class Person.
  99.  
  100. *721*Recall that birth takes a string input, creates a new Person, and sets the new Person‚Äôs name attribute equal to the input string. The Person object is delivered to the output-bar terminal to be passed along for further processing. Before you entered the Application Builder, the conception method was the original source of user interaction to set birth in motion. You now replace the modal dialog of conception with a more Macintosh-like modeless interaction using the Add method triggered by the Add button in the Folks Database window.
  101. -----------------------------------------------------------
  102.  
  103. u Option-click the Cancel button of the top Value window, Value of List Item 1, to close*1082* all Value windows at once.
  104.  
  105. u Double-click the dotted background of the Add execution window to open its editable case window.
  106.  
  107. u Drag the case window down and to the right so the case window does not obscure the execution window. This way you can create some code, activate the execution window, step through the evolving method, and then go back to the case window to develop the method further.
  108.  
  109. u Select the left root of the case-window input bar. Option-Command-click to place a new operation, and open the ÀôInfo‚Ķ dialog.
  110.  
  111. u Scroll to select the find-item *842*entry. Read its description and then click the Name pop-up. Press Return to transform the generic operation into a find-item operation. The Window object arriving on the left root of the input bar should be feeding into the left terminal of the find-item operation through a datalink.
  112.  
  113. ___________________________________________________________
  114. NOTE: find-item is a powerful primitive that takes a window or menu as input and searches its item list attribute for a particular object. The name attribute of the found object must match the string input to the right terminal of the find-item operation.
  115.  
  116. In this example, you can quickly reach into the window, find the Edit Text item, and get its text attribute.
  117. -----------------------------------------------------------
  118.  
  119. u Double-click the right terminal of find-item to create and attach a constant operation. Type Name and press Return. Dismiss the ÀôInfo‚Ķ dialog.
  120.  
  121. u Click anywhere in the execution window to make it the topmost, active window. 
  122.  
  123. The Add method performs a rollback*948* from the output bar, which was highlighted and pending execution. The name constant operation is highlighted, ready to pass its value to the right terminal of the*375* find-item operation. The Window object is available on the root of the input bar, ready to be passed to find-item.
  124.  
  125. u Press Return. The Window object and the string, "Name", arrive on the terminals of find-item, which becomes highlighted. Its roots are solid *962*pattern-filled circles indicating that the find-item operation has not yet *357*executed and has not passed along its output.
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145. u Press Return. The execution highlight moves to the output bar, and the find-item roots become hollow circles*958*.
  146.  
  147. u Double-click the right root of find-item to inspect the output the operation has produced. You see the Edit Text object that you called Name in its Name field in the Edit Text editor.
  148.  
  149. u Close the Value window and click the editable case window so you can add more to the Add method.
  150.  
  151. u Click the right root of find-item, and Option-Command-click another operation. Select*390* Get *649**795*from the Opers menu, type text, and press Return.
  152.  
  153. *722*You now have extracted the value in the Edit Text object‚Äôs text attribute. This value, "Johnny", is what you want to name the Person you are about to create. You need only pass this data along to your user-defined method, birth, in class Person.
  154.  
  155. u Click the right root of the text get operation, and Option-Command-click another operation. Type //birth and press Return.
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170. The Add method now meets its initial design goal of creating a new Person and giving him or her the name from the Edit Text field of the Folks Database window. To confirm this:
  171.  
  172. u Close the case window of the Add method. Click the Add method execution window to make it active if it is not already. The Add method rolls*949* back its execution to the point at which the text get operation is ready to execute.
  173.  
  174. u Press Return to execute the text get operation.
  175.  
  176. u Move the pointer over  the terminal of the //birth operation and click and hold the mouse button down to confirm that the string "Johnny" is ready to flow into the birth operation..  Remember, the single-click and hold technique is the fastest way of inspecting data values.
  177.  
  178. u Press Return to execute the birth method.
  179.  
  180. u Double-click the root of the //birth method operation to open a Value window, which confirms that you now have a new Person object named Johnny.
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193. u Press Cancel to close the Value window and press Return to complete execution of the Add method.
  194.  
  195. A design weakness in your Folks Database window is immediately apparent. The name, Johnny, is still in the Edit Text field. You want to avoid having to delete each name entered, and to give a visual cue that the new Person has been created with the new name. To do this, extend the Add method to clear the text attribute of the name Edit Text item. The easiest way to clear the Edit Text field is to perform a text set operation giving this attribute the empty string, " ", as input.
  196. u Press the Add button again to pop up the execution window. Double-click its background to open the editable case window.
  197.  
  198. u The Edit Text object is made available on the left root of the text get operation for further processing. Select the left root of the text get operation, and Option-Command-click a new operation.
  199.  
  200. u Select Set *660**806*from the*980* Opers menu.
  201.  
  202. u Type text and press Return.
  203.  
  204. u Double-click the right terminal of the text set operation to attach a Constant operation to this input.
  205.  
  206. u Type " " (quotation mark quotation mark, with no space in between) and press Return.
  207.  
  208. u You may want to drag a few operation icons around to avoid overlaps or crossed datalinks.
  209.  
  210. ===========================================================
  211. TIPS: You can drag comments, and toggle hiding/showing them by Command-clicking on the roots or terminals to which they are attached.
  212.  
  213. Option-arrow-keys will nudge selected Prograph objects one pixel at a time. 
  214. ===========================================================
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229. u Close the case window and press Return a few times to walk completely through the Add method. Now when the Add method finishes, the Edit Text field is cleared for the next name.
  230.  
  231. u Switch context or click on any open editor window to suspend*48**1028* your application and bring up the Prograph Editor menu bar.
  232.  
  233. u    Select*258* Debug *613*in the Exec menu. The check mark on this item disappears, indicating you have left Debug mode. Your application now runs uninterrupted by execution-window pop-ups.
  234.  
  235. u    Click the Folks Database window or switch context to continue running your application.
  236.  
  237. u Create a few new people. The process of adding new people is cleaner and more convenient to the user.
  238.  
  239. u Switch context and activate*332* Debug by selecting it in the Exec menu, to prepare for your next round of interface enhancement.
  240.