Monday, August 30, 2010

Powerbuilder interview question _part 6

INHERITANCE

1. What is inheritance?
Inheritance is the ability to define a new classes from existing ones. Inheritance lets the developer derive (make) a new class (object type )from existing base class. It enables you to build windows, user objects, and menus that are derived (made) from existing objects. Descendant inherits all of the components of the ancestor. It includes attributes, variables, structures, functions, events and scripts.

2. What is the benefit of inheritance?
Inheritance ensures consistency in the code and look of objects and helps initial coding.

3. What is SUPER keyword and how it is used?
PB has 4 special keywords used to refer to an object without having to specify its name:
This—used for a reflexive reference to the object itself (window, control or user object)
Parent—refers to the window that owns or contain the object making the reference
ParentWindow—reference from a menu item referring to the window to which is attach
Super—refers to the ancestor script
1. This is equivalent to the following more verbose (Syn. using more words) call (assuming the name of the ancestor is w_ancestor,
Call w_ancestor cb_calculate::clicked
This calls the script in the clicked event in the immediate ancestor of the cb_calculate
Call super :: Clicked

4. When we change an attribute in an inherited control, we break the connection to the parent for that attribute only. -- TRUE

5. Which PowerBuilder objects can be inherited?
MENUS; USER OBJECTS; WINDOWS

6. Give an example of how you would use inheritance in your project?
I used the base (class) library to inherit it for all my application objects in order to increase the development process.
A standard company logon window that requires minimal changes.


7. How can you customize a descendant?
We can change the values of attributes and variables, extend/override the script, add controls, reference an ancestor’s functions, events, or structures, or declare variables, events, functions and structures for the descendant.

8. Can you delete a MenuItem in the descendant menu if it was created in the ancestor one?
We cannot delete a MenuItem in the descendant menu if it was created in the ancestor one but we can make it disabled and invisible.

9. What happens when you change the ancestor?
The changes apply to the all descendants.

10. What can you do with ancestor scripts?
We can Override or Extend the ancestor script at the descendant level. We can also call it from the descendant script.
11. Let’s say, you developed a window w_customers. After some time you developed a base ancestor window w_base_win and want to use all functionality that you put in this ancestor in your w_customers window. How can you do this?
By exporting w_customers, editing the exported file and importing it back.

12. How many levels of inheritance do you usually use?
I try not to use more than 3 levels, because my opinion is that each extra level decreases the performance and makes the code more difficult to read, but Powersoft says that with PB5, if we use the right structure of inheritance, it will increase the performance.

13. How can you call an ancestor script from a descendant object? (see pronouns)
There is CALL command that calls an ancestor script from a script for a descendant object. For example, CALL w_emp :: Open
CALL w_emp.cb_close :: Clicked
We can also use the word SUPER to refer to the immediate ancestor (parent). For example, to call the parent’s Clicked script: CALL SUPPER :: CLICKED
You can name directly the ancestor in the call or use the reserved word SUPER
Call Super :: Clicked

14. How can you override ancestor script at descendent level with no script in descendant?
Put comments //

15. How can you customise a Descendant?
Override or extend script, add controls, change value of attributes and variables.

16. How can you change an object’s ancestor without recording it?
Export the descendant, edit it (changing the name of the ancestor) and import it back.

17. Can you inherit a DataWindow?
We cannot do it directly, but we can create a standard UserObject of DataWindow type (which can be inherited) and use it instead of DataWindow controls. You use the same method when you need to inherit any control.



18. What is the difference between inheriting and copying an object?
When you change the ancestor object the changes are reflected in all the descendants.
When copying, you have to manually make changes. In copying you can delete or add the same control from the window. In descendant you cannot delete control just can make it nonvisible.
P.S. Changes to an attribute in the ancestor affect only the descendant on which that attribute has not been changed. WHEN YOU CHANGE ATTRIBUTE IN AN INHERITED CONTROL, YOU BREAK THE CONNECTION TO THE PARENT FOR THAT ATTRIBUTE ONLY. To re-establish the link to the parent you can click on the control and choose Edit/Reset Attribute

19. How can you execute ancestor script from the descendant?
CALL calls an ancestor script from a script for a descendent object. Call Super::Clicked (execute the script on the clicked event in ancestor). You can call scripts for events in an ancestor of the user object, menu, or window. You can also call scripts for events for controls in an ancestor of the user object or window. The following statement calls a script for an event in an ancestor window.
CALL w_emp::Open
The following statement calls a script for an event in a control in an ancestor window.
CALL w_emp`cb_close::Clicked
In some circumstances, you can use the Super reserved word when ancestor object is the descendant object's immediate ancestor.

20. How you can call function in ancestor from descendant?
w_parent::functionname(arg)
If the descendant has a function with the same name
Supper:: wf_functionname( )
You can call function from the descendant: just put the function name and give it the arguments. The only exception is if another function in the descendant window has been named exactly the same as the ancestor window function. In this case calling this name would call the descendant window’s function, not the ancestor. The solution to this problem depends on where you are making the call from. If you are calling the ancestor function from the window script (open or other event) you can:
w_parent::functionname(arg)
If you are calling the function from within a control or user object event, you must create a new descendant window function that does nothing but make a qualified call to the ancestor window function (as previously). Then you call the new descendant window function from within the control or user object.

21. You are working with inherited windows, and your application does not work or produces ambiguous errors. You are tracing the program though the DEBUGGER, and still - nothing. What can you do next?


22. Which of the following can be inherited? (pick all)
-window -Y
-data window - Y
-application
-function
-query
-script
-user object -Y

23. You can create, delete and change controls in a descendent? False

24. A descendant can only have one ancestor? False

25. What is SUPER keyword and how it is used?
SUPER is a keyword used to make a reference to an object without having to specify its name: When you write a script for a descendant object or control, you can call scripts written for any ancestor. You can directly name the ancestor in the call, or you can use the reserved word Super to refer to the immediate ancestor (parent). If you are calling an ancestor function, you only need to use Super if the descendant has a function with the same name and the same arguments as the ancestor function. Otherwise, you would simply call the function with no qualifiers.You can only use Super in an event or function associated with a direct descend-ant of the ancestor whose function is being called.

INSTANTIATION

1. How do you instantiate one window from another?
Every object belongs to an object class and is called an instance of the class. Every window object, for example, is an instance of the “window” class. You can think of the object class as the “prototype” or “model” for the object. When you develop a PB appli-cation, you design its object classes. When you run the application, the object instances come into existence. The process of creating an object from an object class is called instantiation. Instantiation always occurs at runtime. For visual objects, instantiation typically occurs The objects you declare are themselves a data type. These kinds of data types are called instance of an object. Instantiation creates an instance of the same object in memory.
We have to declare a window object as a datatype and open it.
w_main w_main1, w_main2
OPEN(w_main1)
OPEN(w_main2)

2. What do you need Instantiation in your application for?
When we want to display several windows that are identical in structure but have different data values.

3. Give a definition of an instance of a window?
Instance is a copy of a window in memory. More than one instance of the same window object can be created in memory.

4. How can you create instances of the same window object?
1. Declare a variable of type w_name :
w_name w_my_window
2. To create an instance we use function open( )
open(w_my_window)
We can create an array of instances of the window. Saving a window in the Window painter saves the definition of the window and the definition becomes a class (a new data type) with the same name as the window. To create an array of instances of a window, declare an array of the data type of the window. For example:
w_employee_address w_ea_inst[5]
Tip: We usually create multiple instances of a pop-up or child window rather than a main window. Or we can create an instance of a window in the local script with a local variable of datatype of this window and call this script each time we need to create a new instance of the window.
Downside: We will not be able to call these windows by name: the handle to the window created this way is lost as soon as the script ends.

5. What the difference between Class and Instance?
Class is in data storage (hard drive). Instance is in memory. Instantiation is a process of creating of instance of an object from a class.

Libraries

1. What is Regenerate option in the Library painter? When is it most useful?
Regenerating could be called “recompiling”. It could also be understood as “synchroniz-ing” the source and the object versions of the object. Although the objects you create and modify are compiled when they are saved, sometimes it is necessary to recompile them. When? When you make a change to an ancestor window that has many descendants, the changes can be immediately rippled throughout all the child windows through regenerati-on. Or when you upgrade to a new version of PB, it is very likely that there are changes in the way compiles are done. The new version should regenerate all your source code to update it.
Tip: if you notice strange behavior or inconsistencies in the way your application works, it never hurts to regenerate the objects to be sure that everything is in synch. It might take several re-generations to fix the problem. If you use inheritance, you have to regenerate for each level of inheritance, because on the first pass one highest-level ancestor object will get fixed, but the descendant might have been regenerated before the ancestor object was touched. The second pass will fix the descendant object. A way around this is to regenerate inheritance trees from the object browser. It regenerates the ancestor first and then each descendant.

2. The Library List shows the DOS path to PowerBuilder…?

3. Why should you optimize libraries?
The library entity can become fragmented over time, increasing seek time.

4. What is Check-in, Check-out options on a Library Painter?
The Source menu functions provide project-team source control for your library—the ability to make sure that two people don’t try to edit the same object at the same time. PB has a rudimentary level of source control capability built into it. Or third-party product, such as Intersolv’s PVCS can be integrated into PB. It lets you “check out” an object by copying it from the main library to another library where, presumably, only one person can modify it. Later, you “check in” the object by copying the modified version back into the main library. While you have an object checked out, its original version remains in the library but other people are restricted to “read-only” access.
(What is the usage of the check in/check out feature in PB?)
When more than one programmer is working on the project, you want to prevent two users from modifying a library entry at the same time. To control access to library entries, you can use check in and check out. When you check out an entry, PB makes a copy of the entry, stores it in a specified library, (e.g. a test or development library), and sets the status of the entry to check it out. As long as the status of an entry is ‘checked out’, you can change only to the working copy. If you or another user tries to open the original copy, PB displays a warning message. When you finish working with the entry that you checked out, you can check in entries to replace the entry in the original library with the working copy of the entry. Check in clears the check out status from the entry, and deletes the working copy from the library in which it is saved.

MDI
1. What is an MDI application ?
MDI application is a frame used to manage multiple documents of the same or different types within one.

2. What is Microhelp? Where do you define it?
Microhelp is additional info about a MenuItem which is used to help the user understand what the MenuItem does. We define the Microhelp text in the Menu painter as part of the process of creating the Menu. It only displays if the frame window of the application is of the type MDI Frame with Microhelp.

3. Where do all Menus in an MDI application display?
All Menus, display in the menu bar of the frame window.

4. Which menu applies to an open sheet of a document type that has been
defined without its own Menu?
When a sheet without a Menu is opened, it uses the current Menu, that is, the Menu that was current when the sheet was opened.

5. What are the parts of MDI frame?
TitleBar
MenuBar
ToolBar
Client Area
Status Area
Frame Window

5. What is an MDI frame?
MDI stands for Multiple Document Interface. MDI window is a frame window in which we can open Multiple Documents Windows (sheets) and move around the sheets. An MDI frame is a window whose main purpose is to be a container for child windows, called sheets.

6. What types of an MDI frame do you know?
There are 2 types of an MDI frame windows: MDI frame and MDI frame with micro help.

7. What is the difference between SDI and MDI frame?
MDI allows the user to work with more than one document at a time.
SDI allows to work with only one document.

8.What is the difference between MDI frame and MDI frame with micro help?
MDI frame doesn’t have microhelp utility.
MDI frame with micro help has the microhelp on the bottom of the window.

9. What is a MDI_1 object? Can we place any controls on MDI_1?
MDI_1 is a client area or workspace within the frame between the toolbar or menu and status area (microhelp) in which open sheet is displayed. When we create and save an MDI frame, PB automatically creates a control called MDI_1. PB uses MDI_1 to identify the client area, the area that holds sheets. We can place any controls on MDI_1. We have to count the height, the width of a control and extract them from the client area.

10. Does MDI_1 have events? What are they?
NO. It does not have any events.

11. Is it a good idea to use CloseQuery Event in MDI window?
Yes. It is a good idea to send a message to the user about to exit from the application.
For example:
MessageBox(“Question?”, ”Are you sure you want to exit from the application?”)

12. How do you check if there are any MDI Sheets currently existing?
IsValid (w_name) determines whether the window is open

13. You have an MDI Window, Sheet 1 with Menu and Sheet 2 without the Menu.
You open Sheet 2 after Sheet 1. Which Menu will have Sheet 2 MDI Menu or Sheet 1 Menu?
It will have the Menu of Sheet1 as the last Menu that was displayed on the MDI window.
A sheet can have its own menu, but its not required to.

14. How do the Application components communicate with one another?
Direct access or manipulation by calling a function, trigger or posting an event using global variables, passing parameters.

15. How do we send parameters between two already opened windows?
n global variables;
n shared variables;
n send parameters by MessageObject using function Send( )

16. How can two sheets within MDI frame communicate with one another?
Global variable
Shared variable
Message object




MDI Applications

17. What is MDI?
MDI is an application style that we use to open multiple windows (sheets) in single window and move among the sheets. Usually MDI has a menu bar client area and Status area (if it is MDI with Microhelp)

18. What functions do we usually use working with MDI?
OpenSheet() - to open sheets inside the MDI frame GetActiveSheet() to keep track which sheet is active now, ArrangeSheet() to arrange sheet’s layout.

19. How can we display information to the users in the status area?
We can associate microhelp with the control defining its Tag attribute and then we will use SetMicroHelp() function to display this tag attribute.

20. How can we display toolbar picture under the MenuItem?
We have to associate a toolbar picture with MenuItem in the Menu Painter.

21. What is the function to open an MDI frame window?

22. What is the function to open a response window from an MDI sheet?

23. How do you use OpenSheetWithParm?
(Opens a sheet within an MDI frame window and creates a menu item for selecting the sheet on the specified menu, as OpenSheet does. OpenSheetWithParm also stores a parameter in the system's Message object so that it is accessible to the opened sheet.)
Applies to Window objects. Syntax:
OpenSheetWithParm ( sheetrefvar, parameter {, windowtype }, mdiframe {, position {, arrangeopen } } )
Example:
OpenSheetWithParm(w_child_1, "MA", MDI_User, 2, Original!)

MENU

1. What is purpose of a Menu object?
A Menu object is a visual object that provides the user with lists of commands, options, or alternate ways of performing a task.

2. What types of Menus do you know ?
DropDown
Cascading
Pop-up

3. What is the difference between the Clicked and Selected event of a MenuItem?
The Clicked event occurs when the user clicks the mouse on the MenuItem or selects the MenuItem with a keystroke and presses Enter.
The Selected event occurs when a user uses the arrow keys to move to a MenuItem or moves the mouse pointer to the item and holds the button down.

4. (fill in the blank) The ellipsis (…) is used after a MenuItem to indicate that a window will appear requesting more information before the command can be executed.

5. (fill in the blank)The underlined character is used before a letter in the text of a MenuItem to assign the letter as an accelerator key for the MenuItem.

6. What is the difference between an accelerator key and a shortcut key in the
way a user uses them to initiate a command or select an option on a Menu ?
Accelerator keys and shortcut keys provide alternative means of invoking commands or selecting options represented by the MenuItems to which they are assigned.
A shortcut key is a single keystroke or a combination of keystrokes (Ctrl + N or F1) annotated to the right of MenuItem. An Accelerator key underlines a character in the Menu or MenuItem. When the Accelerator key is in a Menu on the Menu bar, the user may press Alt + character to select the Menu.

7. What kind of menus do you use?
A DropDown menu is a menu under an item in the menu bar
Cascading menu is a menu to the side of an item in a DropDown menu.
Pop-up menu is not connected with a menu bar.

8. What attribute of the MenuItem do you know?
Checked. Whether the MenuItem displays with a check mark next to it.
Enabled. Whether the MenuItem can be selected.


14. How do you use menus in the window?
We can associate a menu with a window in the window style window or display a pop-up menu in the window using the Pop-up Menu function.

MESSAGE OBJECT

1. What is the Message object. How do you use it? Why do you use it?
Objects work with one another by sending messages. A message is a subroutine call directed at an object. Every object has a predefined set of subroutines (in PB methods) that you can call to send messages to the object.
Object.Method (parameters)
In PB, there are three types of messages:
1, 2. Functions & events which are collectively called “methods”;
3. Properties.
In PB, every object has a set of functions, events and properties for receiving messages. PB also has functions that are not directed to an object, such as a MessageBox.
MessageBox(“Hello”, “How are you?”)
For the transaction object, you do not use the object.function syntax. Instead, you use standard SQL syntax. A Message object is a PowerBuilder-defined global object. When we use functions OpenWithParm( ), OpenSheetWithParm( ), CloseWithReturn( ) (for response window only) specified parameters will be passed through the MessageObject. We can use this Message object to store a parameter when opening or closing a window.

2. How do you use OpenSheetWithParm( )?
We use function OpenSheetWithParm( ) to pass parameters between two Windows (sheets) in (MDI) application using Message Object’s attributes StringParm, DoubleParm or PowerObjectParm, depending on the variable datatype. The Parameters will be stored in MessageObject. OpenSheetWithParm( ) stores the parameter in the system's Message object so that it is accessible to the opened sheet. We use OpenWithParm( ) to open a window that is not an MDI sheet and pass information to the window. We use the OpenSheetWithParm( ) function to open MDI sheets when we need to pass information to the sheet that is being opened or use the information to open the sheet.

3. State briefly and in general terms when you would use each of the following functions. Be sure your answer reflects the difference between the two functions.
n OpenWithParm( )
n OpenSheetWithParm( )

4. (true or false) The Open() and OpenWithParm() are only used in (SDI) applications.

5. Assume you are coding the script for the Open event of a window to which a number has been passed. Code the statement that tests whether the value is greater than 100.

6. Can a Message object Pass Parameters?
Yes, using Send () command

7. What functions can you use to pass parameters between the Windows in PB?
1. OpenWithParm( )
2. OpenSheetWithParm( )
3. CloseWithReturn( )

8. How do OpenWithParm() and CloseWithReturn() functions pass parameters?
Using Message Object’s attributes StringParm, DoubleParm, PowerObjectParm depending on a variable datatype. OpenWithParm( ) also stores a parameter in the system’s Message object so that it is accessible to the opened window. Closes a window and stores a return value in the Message object. Use CloseWithReturn() only for response windows.

9. What is the usage for StringParm, DoubleParm and PowerObjectParm attributes of Message Object?

10. What attribute in the Message Object do we have to use if we want to store a Structure in it?
We have to use the PowerObjectParm attribute.

11. What is the Message Object?
It is a PB System object that is used to communicate parameters between windows. When we Open and Close them and in TriggerEvent and PostEvent functions.

12. What attributes of System Object do you use to pass parameters windows?
DoubleParm for numeric parameters, StringParm for strings and PowerObjectParm for any PB objects including structure.

013. What function do you use to communicate parameters between windows?
OpenWithParm and CloseWithReturn power script function.

14. How can you handle Error Messages (examples)?
Put some code into DB Error event (using SetActionCode)
int err_code
If SQLDB.Code <> 0 Then
MessageBox (“DB Error:”, “Number” + string (sqldbcode) + “” + &
sqlerrtext, StopSign!)
return 1
End if

33. What is the Message object? How do you use it? Why do you use it?
Objects work with one another by sending messages. A message is a subroutine call directed at an object. Every object has a predefined set of subroutines (in PB methods) that you can call to send messages to the object.
Object.Method(parameters)
In PB, there are three types of messages:
1, 2. Functions & events which are collectively called “methods”;
3. Properties.
In PB, every object has a set of functions, events and properties for receiving messages. PB also has functions that are not directed to an object, such as a MessageBox.
MessageBox(“Hello”, “How are you?”)
For the transaction object, you do not use the object.function syntax. Instead, you use standard SQL syntax.
Name Pronouns
1. Describe the circumstances under which you would use the pronoun This instead of the name of the object it represents.
The pronoun This refers to the MenuItem, object, or control for which the script is written.

2. What is SUPER keyword and how it is used?
SUPER is a reserved word used to refer to the immediate ancestor from a descendent level… If we are calling a script from an ancestor we have to use
Call SUPPER :: Clicked
This example calls the Clicked Event in the ancestor object. If you are calling an ancestor function, then you only need to use SUPER ::
SUPER :: wf_name( arguments )
If the script is for an event in a control : Call ancestor window control :: event or a user object in an ancestor window : Call ancestor window object :: event

3. What if you need to call a function from not an immediate ancestor?
We have to specify the full path to that function. For example:
w_name :: function_name( ) to call an event from not an immediate ancestor
Call ancestor window :: event.

4. What are :THIS, PARENT, PARENTWINDOW clauses?
They are Name pronouns and used to refer to current objects or controls instead of using actual names. This is used to refer to an object or control from any script coded for it. Parent is used to refer to the window from any script for a control on window. ParentWindow is used to refer to the window from a MenuItem script at execution time.

5. What is the difference between reserved word Parent an ParentWindow, When are they used in the script for the MenuItem?
ParentWindow refers to the window that associated with a Menu. ParentWindow can be used only in scripts for MenuItems. Parent is used in the following scripts :
1. A script for a control in a window.
2. A script for a custom UserObject.
3. A script for a MenuItem.
When we use Parent in the script for a MenuItem, Parent refers to the MenuItem on the level above the MenuItem the MenuItem the script is for. ParentWindow is the name of the window object that owns the menu.


6. What are Object Name pronouns and how do use them?
Name Pronouns are reserved words that are used to refer to objects or controls instead of using actual name. They are:
This is used to refer to an object or control from within any script coded for it.
Parent is used to refer to the window from any script for a control on the window.
ParentWindow can be used only in scripts for MenuItems.
Super is a reference used in a script of an inherited object to refer to the script in its immediate ancestor (parent).
When we use Parent in a script for a control, it refers to the window that contains the control. When we use Parent in the script for a MenuItem, Parent refers to the MenuItem on the level above the MenuItem the script is for. When we use Parent in a script for a control in a custom UO, Parent refers to the UO. The pronoun ParentWindow refers to the window with which the menu is associated at execution time. ParentWindow can be used only in scripts for MenuItem. The pronoun This refers to the window, UO, MenuItem, application object, or control itself. When we write a script for a descendant object or control, we can call scripts written for many ancestor. We can directly name the ancestor in the call, or we can use the reserved word Super to refer to the immediate ancestor (parent) CALL Super :: Clicked.

7. What reserve word for window do you know?
ParentWindow type refer to the window that the menu is associated with at runtime.
We can use ParentWindow to refer to attributes of the window a menu is associated with but not refer to attributes of controls or user objects in the window.

No comments:

Custom Search