Buliding Object-Oriented Applications in PowerBuilder  Module 4 : Object Instances
Objectives <ul><li>Outline what happens when a window is opened in PowerBuilder </li></ul><ul><li>Identify the steps invol...
Topics <ul><li>Object Instances in PowerBuilder </li></ul><ul><li>Instantiating Visual Classes Using Open( ) </li></ul><ul...
Object Instances <ul><li>Multiple objects, or instances, can be created from the same definition (class) </li></ul><ul><li...
<ul><li>At execution time, windows are object instances </li></ul><ul><li>Each window has its own unique set of property v...
Instantiating Visual Classes — Open( ) <ul><li>Open(w_cust) creates an instance of the class w_cust </li></ul><ul><li>Othe...
Instantiating Visual Classes — Open( ) <ul><li>Instances should be removed from memory when they are no longer needed to f...
Instantiating Visual Classes — Open( ) <ul><li>Execute the Open( ) function </li></ul><ul><li>Search the class pool </li><...
Instantiating Visual Classes — Open( ) <ul><li>Search the libraries  </li></ul><ul><li>Copy the class definition to the cl...
Instantiating Visual Classes — Open( ) <ul><li>Create a global reference variable (w_cust) </li></ul><ul><li>Create an ins...
Instantiating Visual Classes — Open( ) <ul><li>Create a visual manifestation of the object </li></ul>A.PBLB.PBLetc. Global...
What Happens During Instantiation? <ul><li>A reference variable:  </li></ul><ul><ul><li>Is required to store the pointer t...
Resolving Ancestor References <ul><li>Class pool is searched for class definition </li></ul><ul><li>Class definition is lo...
PowerBuilder Data Types <ul><li>Standard data types </li></ul><ul><li>Class data types </li></ul><ul><li>Structures </li><...
Standard Data Types <ul><li>Standard data types </li></ul><ul><ul><li>Integer, string, date, and so on </li></ul></ul><ul>...
Class Data Types <ul><li>Declared in the same way as a standard variable: </li></ul><ul><ul><ul><li>w_cust  lw_win </li></...
Structures  <ul><li>Defined in the Structure painter </li></ul><ul><li>Property-only class — cannot define methods </li></...
Structure Painter
Structures <ul><li>Example: </li></ul><ul><ul><ul><ul><li>str_work  lstr_work, lstr_work2 </li></ul></ul></ul></ul><ul><ul...
Instantiating Nonvisual Classes <ul><li>Use the CREATE command to instantiate a nonvisual class </li></ul><ul><ul><li>Exam...
Instantiating Classes — CREATE <ul><li>Class definition is located and the instance is built </li></ul><ul><li>Reference v...
Instantiating Classes <ul><li>Visual classes (windows, menus, controls, and so on) can be instantiated with CREATE  </li><...
Instantiating Classes — PopMenu( ) <ul><li>A menu can be made visible as a popup menu </li></ul><ul><ul><ul><li>m_utility ...
Instantiating Data Stores <ul><li>A data store is like a DataWindow control, but has no visual component </li></ul><ul><li...
Summary <ul><li>You instantiate a window by calling a form of the  Open( ) function.  You destroy the instance by calling ...
Summary Questions
Lab Setup <ul><li>What you will need to do the lab: </li></ul><ul><ul><li>Examine source code for any user-defined class i...
Lab Debriefing <ul><li>What is the name of the immediate ancestor? </li></ul><ul><li>What is the first command executed wh...
Lab DeBriefing <ul><li>Script of ue_RButtonDown in w_master: </li></ul><ul><li>m_master_util   lm_master_util </li></ul><u...
Lab Debriefing <ul><li>Code for the rbuttondown event: </li></ul><ul><li>this.post Event ue_RButtonDown()  or </li></ul><u...
Lab Debriefing <ul><li>1.   Right-click the status bar of the frame window.  What happens?  Right-click inside the frame w...
 
Upcoming SlideShare
Loading in...5
×

Booa8 Slide 04

603

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
603
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Booa8 Slide 04

    1. 1. Buliding Object-Oriented Applications in PowerBuilder Module 4 : Object Instances
    2. 2. Objectives <ul><li>Outline what happens when a window is opened in PowerBuilder </li></ul><ul><li>Identify the steps involved in creating a transaction object </li></ul><ul><li>Define an object reference variable </li></ul><ul><li>Compare and contrast standard, class, and structure data types </li></ul><ul><li>Explain how to use the CREATE command to instantiate nonvisual and visual classes </li></ul>
    3. 3. Topics <ul><li>Object Instances in PowerBuilder </li></ul><ul><li>Instantiating Visual Classes Using Open( ) </li></ul><ul><li>Resolving Ancestor References </li></ul><ul><li>Data Types </li></ul><ul><li>Instantiating Nonvisual Classes Using CREATE </li></ul><ul><li>Instantiating Visual Classes Using CREATE </li></ul>
    4. 4. Object Instances <ul><li>Multiple objects, or instances, can be created from the same definition (class) </li></ul><ul><li>The process of creating an object instance from a class definition is called instantiation </li></ul><ul><li>Each instance has its own memory space </li></ul>
    5. 5. <ul><li>At execution time, windows are object instances </li></ul><ul><li>Each window has its own unique set of property values </li></ul>Example of an Instance in PowerBuilder
    6. 6. Instantiating Visual Classes — Open( ) <ul><li>Open(w_cust) creates an instance of the class w_cust </li></ul><ul><li>Other functions that instantiate windows: </li></ul><ul><ul><li>OpenWithParm( ) </li></ul></ul><ul><ul><li>OpenSheet( ) </li></ul></ul><ul><ul><li>OpenSheetWithParm( ) </li></ul></ul>
    7. 7. Instantiating Visual Classes — Open( ) <ul><li>Instances should be removed from memory when they are no longer needed to free system resources </li></ul><ul><li>Window instances are &quot;destroyed&quot; (removed from memory) using: </li></ul><ul><ul><li>Close( ) </li></ul></ul><ul><ul><li>CloseWithReturn( ) [response windows only] </li></ul></ul>
    8. 8. Instantiating Visual Classes — Open( ) <ul><li>Execute the Open( ) function </li></ul><ul><li>Search the class pool </li></ul>Class pool Open(w_cust) Global memory No hit! w_frame w_main Instance pool
    9. 9. Instantiating Visual Classes — Open( ) <ul><li>Search the libraries </li></ul><ul><li>Copy the class definition to the class pool </li></ul>Class pool w_cust Global memory w_cust w_frame w_main A B C w_app w_cust, w_main w_frame etc. Instance pool
    10. 10. Instantiating Visual Classes — Open( ) <ul><li>Create a global reference variable (w_cust) </li></ul><ul><li>Create an instance of w_cust in the instance pool </li></ul><ul><li>Populate the variable with the pointer to the instance </li></ul>A B C Global memory w_cust w_frame w_main Class pool Instance of w_cust w_cust w_cust w_app w_cust w_main w_frame etc. Instance pool
    11. 11. Instantiating Visual Classes — Open( ) <ul><li>Create a visual manifestation of the object </li></ul>A.PBLB.PBLetc. Global memory w_cust w_frame w_main Class pool Instance of w_cust w_cust w_cust w_app w_cust w_main w_frame etc. Instance pool
    12. 12. What Happens During Instantiation? <ul><li>A reference variable: </li></ul><ul><ul><li>Is required to store the pointer to the instance </li></ul></ul><ul><ul><li>Has a data type corresponding to the class type </li></ul></ul><ul><li>The class pool stores class definitions, including all class methods (events and functions) </li></ul><ul><li>The instance pool stores each instance, including all of its properties </li></ul><ul><li>Instantiation of an object requires that all ancestor class definitions are loaded in the class pool </li></ul>
    13. 13. Resolving Ancestor References <ul><li>Class pool is searched for class definition </li></ul><ul><li>Class definition is loaded from a library, if not in the pool </li></ul><ul><li>Definition is scanned for references to other ancestors </li></ul><ul><li>Ancestor class definitions are loaded (if necessary) and scanned for ancestors </li></ul><ul><li>When all the references are resolved, the instance is created </li></ul><ul><li>Note: PowerBuilder system classes are loaded at startup </li></ul>
    14. 14. PowerBuilder Data Types <ul><li>Standard data types </li></ul><ul><li>Class data types </li></ul><ul><li>Structures </li></ul>
    15. 15. Standard Data Types <ul><li>Standard data types </li></ul><ul><ul><li>Integer, string, date, and so on </li></ul></ul><ul><ul><li>Assignment statement copies values when executed </li></ul></ul><ul><li>Standard data types – Constants </li></ul><ul><ul><li>Declaration prefaced with CONSTANT keyword </li></ul></ul><ul><ul><ul><li>CONSTANT long icl_yellow = 655635 </li></ul></ul></ul><ul><ul><ul><li>CONSTANT time ict_compiled = Now( ) </li></ul></ul></ul><ul><ul><li>Cannot be changed at execution time </li></ul></ul>
    16. 16. Class Data Types <ul><li>Declared in the same way as a standard variable: </li></ul><ul><ul><ul><li>w_cust lw_win </li></ul></ul></ul><ul><ul><ul><li>window lw_win </li></ul></ul></ul><ul><li>Stores pointer to an instance </li></ul><ul><li>Assignment statement copies the pointer value, not the instance, when executed </li></ul><ul><li>IsValid( ) function </li></ul>
    17. 17. Structures <ul><li>Defined in the Structure painter </li></ul><ul><li>Property-only class — cannot define methods </li></ul><ul><li>Assignments copy all the data values, not the reference </li></ul><ul><li>Automatic instantiation </li></ul><ul><ul><li>When variable is allocated, instance is automatically created </li></ul></ul><ul><ul><li>When variable falls out of scope, instance is automatically destroyed </li></ul></ul>
    18. 18. Structure Painter
    19. 19. Structures <ul><li>Example: </li></ul><ul><ul><ul><ul><li>str_work lstr_work, lstr_work2 </li></ul></ul></ul></ul><ul><ul><ul><ul><li>lstr_work.s_name = “Sam” </li></ul></ul></ul></ul><ul><ul><ul><ul><li>lstr_work2 = lstr_work </li></ul></ul></ul></ul><ul><ul><ul><ul><li>lstr_work.s_name = “Bill” </li></ul></ul></ul></ul><ul><ul><li>Question: What is the value of lstr_work2.s_name? </li></ul></ul>
    20. 20. Instantiating Nonvisual Classes <ul><li>Use the CREATE command to instantiate a nonvisual class </li></ul><ul><ul><li>Example: </li></ul></ul><ul><ul><li>transaction ltrans_temp </li></ul></ul><ul><ul><li>ltrans_temp = CREATE transaction </li></ul></ul>
    21. 21. Instantiating Classes — CREATE <ul><li>Class definition is located and the instance is built </li></ul><ul><li>Reference variable is assigned the object's address </li></ul>Local memory Global memory Class pool Instance pool instance 1 of transaction w_cust w_frame transaction transaction SQLCA transaction Itrans_temp
    22. 22. Instantiating Classes <ul><li>Visual classes (windows, menus, controls, and so on) can be instantiated with CREATE </li></ul><ul><li>Example: </li></ul><ul><ul><ul><li>m_utility lm_util lm_util = CREATE m_utility </li></ul></ul></ul><ul><li>Note: No visual manifestation of the instance is created </li></ul><ul><li> (that is, it will have no graphical component) </li></ul>
    23. 23. Instantiating Classes — PopMenu( ) <ul><li>A menu can be made visible as a popup menu </li></ul><ul><ul><ul><li>m_utility lm_util </li></ul></ul></ul><ul><ul><ul><li>lm_util = CREATE m_utility </li></ul></ul></ul><ul><ul><ul><li>lm_util.m_edit.PopMenu(xpos, ypos) </li></ul></ul></ul><ul><ul><ul><li>... </li></ul></ul></ul><ul><li>PopMenu( ) creates a visual manifestation of the instance </li></ul>
    24. 24. Instantiating Data Stores <ul><li>A data store is like a DataWindow control, but has no visual component </li></ul><ul><li>DataStores are instantiated with CREATE </li></ul><ul><ul><ul><li>datastore lds_hold </li></ul></ul></ul><ul><ul><ul><li>lds_hold = CREATE datastore </li></ul></ul></ul><ul><ul><ul><li>Lds_hold.DataObject = “d_customer” </li></ul></ul></ul><ul><ul><ul><li>lds_hold.SetTransObject(SQLCA) </li></ul></ul></ul><ul><ul><ul><li>lds_hold.Retrieve( ) </li></ul></ul></ul><ul><ul><ul><li>... </li></ul></ul></ul>
    25. 25. Summary <ul><li>You instantiate a window by calling a form of the Open( ) function. You destroy the instance by calling a form of Close( ). </li></ul><ul><li>The class pool stores the class definition. The instance pool stores the object. </li></ul><ul><li>Structures are automatically created and destroyed. </li></ul><ul><li>A reference variable is a pointer to an object. </li></ul><ul><li>You instantiate a nonvisual object using CREATE. </li></ul><ul><li>Use a DataStore instead of an invisible DataWindow control. </li></ul>
    26. 26. Summary Questions
    27. 27. Lab Setup <ul><li>What you will need to do the lab: </li></ul><ul><ul><li>Examine source code for any user-defined class in a PBL </li></ul></ul><ul><ul><li>Understand the syntax for instantiation, inheritance, and script execution </li></ul></ul><ul><ul><li>Instantiate an object using the CREATE command </li></ul></ul><ul><ul><li>Use the PopMenu( ) function </li></ul></ul>
    28. 28. Lab Debriefing <ul><li>What is the name of the immediate ancestor? </li></ul><ul><li>What is the first command executed when an instance of this window gets created? </li></ul><ul><li>What are the names of the three control subclasses that are included in this window? </li></ul><ul><li>What are the ancestor classes of these objects? </li></ul><ul><li>What is the first command executed when the Constructor event of p_kids occurs? </li></ul><ul><li>What is the second command executed when the Constructor event of p_kids occurs? </li></ul><ul><li>What is the second command executed when the window is closed? </li></ul>
    29. 29. Lab DeBriefing <ul><li>Script of ue_RButtonDown in w_master: </li></ul><ul><li>m_master_util lm_master_util </li></ul><ul><li>lm_master_util = create m_master_util </li></ul><ul><li>lm_master_util.m_file.popmenu( this.PointerX(), this.PointerY()) </li></ul>
    30. 30. Lab Debriefing <ul><li>Code for the rbuttondown event: </li></ul><ul><li>this.post Event ue_RButtonDown() or </li></ul><ul><li>PostEvent(“ue_RButtonDown”) </li></ul>
    31. 31. Lab Debriefing <ul><li>1.   Right-click the status bar of the frame window. What happens? Right-click inside the frame window. Why does right-clicking inside the frame window have no effect? </li></ul>

    ×