Monday, August 30, 2010

Powerbuilder Interview question _ part 9

STRING FUNCTION

1. What does a string manipulation function Left( ) do?
Obtains a specified number of characters from the beginning of a string. Left(string, n)

2. What does a string manipulation function LeftTrim( ) do?
Removes spaces from the beginning of a string. LeftTrim(string)

3. What does a string manipulation function RightTrim( ) do?
Removes spaces from the end of a string. RightTrim(string)

4. What does a string manipulation function Mid( ) do?
Obtains a specified number of characters from a specified position in a string.
Mid(string, start{, length})

5. What does a string manipulation function Lower( ) do?
Converts all the characters in a string to lowercase. Lower(string)

6. What does a string manipulation function Right( ) do?
Obtains a specified number of characters from the end of a string.
Right( string )

7. What does a string manipulation function String( ) do?
Convert variables of other datatype into sting String ( data, { format } )

8. What does a string manipulation function Trim( ) do?
Removes leading and trailing spaces from a string Trim(string )

9. What is the function of SelectText( )?
Selects text in an editable control. We specify where the selection begins and how many characters to select: editname.SelectText ( start, length )

10. Write a function to find one string within another and return position of that sub-string?
String msg, putin
long NewPos, l_NewPos
msg = mle_text.text
putin = sle_find.text
NewPos = Pos(msg, putin, 1)
l_NewPos = Pos(msg, putin,NewPos)
SetFocus(mle_text)
mle_text.SelectText(l_NewPos,len(putin))

STRUCTURE
1. What is a Structure? What is Structure Data type?
The structure is a collection of one or more related variables of the same or different data type grouped under a single name. There are Global and Object level structure.

2. How do you use a Structure in your script ?
We define structures using the Structure painter. In scripts we must create instances of the structure in order to use them. When we refer to an individual variables within a structure, we need to prefix them with the name of the structure instance.

3. Which attribute of the Message Object is used to pass a structure between windows ?
PowerObjectParm attribute of the Message Object is used to pass a structure between windows as the parameter in the OpenSheetWithParm( ) function.

4. Show me how to send a structure to a function.
You can pass a structure as an argument in user-defined functions. Simply name the structure as the structure data type when defining the argument.

5. Can an array be an element of the Structure? Can a User Object be?
YES. An array and a User Object can be an aliment of the structure. Any object can be an element of the structure.
Example
S_struct s_str
for I = 1 to 10
s_str.array[i] ……..
next

6. How to reference structure variables in the script?
If the structure is Global, you have to declare the variables of this structure type and use dot notation to reference the structure variables. E.g.,
emp_data emp1
emp 1.emp_id =100
If the structure is object level and you want to use it in the script for the object itself declare a variable of this structure type and use dot notation. If you want to make this object level structure accessible outside the object: in the object that defines the structure, declare an instance variable of the structure type. In any script of the application reference a variable in the structure using syntax:
object .instance_variable .variable

7. Could you pass structure as argument in user defined function?
YES. We just have to name structure as a data type when we defining argument.

8. When do you use = operator?
It is used to compare one structure to another structure of the same type.

9. Can an array be an element of the Structure? Can User Object be?
Yes, an array can be in the structure, because it is also a variable that can hold multiple storage values. Unlike an array which has a single variable name and a range of numeric index values, a structure is composed of many variable names that are related in some way. These variables may be of different data types. How to process an array:
s_struct s_str.
For I = 1 to 10
s_struct.array[I] = …

Yes, a user object can be a part of a structure. How to process a user object:
s_str.ou_obj = Create u_obj
open s_structure.window

10. Can you assign a structure to a structure?
Yes, we can copy all elements of a structure to another structure with a single assignment statement. At first, we declare a structure as a class and then assign values of the first structure to another structure.

TARGET OBJECT

1. What are the Target Object events?
DragDrop
DragEnter
DragLeave
DragWithIn

2. What is a drag mode?
A Drag mode is the state of the object when the user has clicked a draggable control and is holding the left mouse button down.

3. In what case did you use Drag and Drop?
We want to create a trash can in our program to make it look more user friendly

4. What are automatic and manual drag modes?
In automatic drag mode, PowerBuilder automatically switches the application into drag mode when the control is clicked. or
DragAuto is a boolean indicating whether PowerBuilder puts the control into a drag mode automatically. DragAuto has these boolean values.
True – when the user clicks the control, PowerBuilder puts the control in drag mode.
When DragAuto is True, clicking a control triggers a DragDrop event, not a Clicked event.
False – when the user clicks the control, PowerBuilder does not put the control in drag mode; we have to call the Drag function to put the control manually into a drag mode.
With manual drag mode, PowerBuilder does not switch the application into drag mode when the control is clicked. We must control when the drag mode is initiated using command drag(Begin!), drag(Cancel!), drag(End!).

TRANSACTION OBJECT

1. When do you use AutoCommit?
1. If you set AUTO COMMIT to FALSE, all SQL commands are part of a transaction and you must issue COMMIT and ROLLBACK commands from time to time to complete your work.
If AUTO COMMIT = TRUE, there are no transactions and each SQL command is immediately committed. In this case explicit COMMIT and ROLLBACK commands in the script have no effect
2. When we need to create a temporary table.
3. When a window has a lot of display activity only.

2. What is a Transaction Object? What is the purpose of a transaction object?
A Transaction Object is an NVO which stores information required to connect to a specific DB.

3. Explain the difference between SetTrans and SetTransObject.
The SetTrans() function provides another way of managing the database connection. SetTrans, which sets transaction info in the internal transaction object for the DW control or DataStore, manages the connection automatically. You do not explicitly connect to the DB; the DataWindow connects and disconnects for each database transaction, which is less efficient but necessary in some situations.
SetTransObject causes a DW control or DataStore to use a programmer-specified transaction object.

USER OBJECT
1. What are Non-Visual User Objects?
Non-visual user object is an object that encapsulates attributes and functions but is not visible to the user. NVO is a collection of business user functions. They can be Custom Class and Standard Class. NVOs are useful because they allow you to encapsulate application operations into objects making them easier to develop, manage and maintain and also to encapsulate all security management for an application into a single object.

2. Explain the purpose of a non-visual user objects
The purpose of non-visual user objects is to define business rules and other processing (which are checked in different windows in your application) that act as a unit. We implement them in PowerBuilder using Class User Objects.

3. What types of a non-visual user object do you know?
There are two types of non-visual user objects :
Standard user object inherits its definition from one built-in, PB NVO such as the Trans-action object or Error object. We modify its definition to make the object specific to our application.
Custom user objects are objects of our own design that encapsulate properties and
functions but are not visible to the user.

Typically, we use Custom Class User Objects to define processing in our application that has no visual component. We typically use class user objects to define processing that acts as a unit; for example if our application calculates sales commissions, we might create a custom class UserObject to perform the commission calculation.

After we build and save a visual user object, we can use it as we use a PB control. We can place it in a window or in other user objects, and we can size it, change its style, and build scripts for its events.
After we build and save a class user object, we declare a variable of the UserObject type and create an inheritance of it using the CREATE statement in a script. Once we have instantiated the class UserObject, its attributes and functions are available within the scope of the variable declaration. After using the UserObject, we destroy it with the DESTROY statement to free up memory.
We can also build new user objects that inherit attributes, events, structures, and functions from an existing user object.

4. What are facilities of the User Objects ?
We define a component once, then reuse it many times as we need without any additional work.

5. Give me an example of Standard & Custom visual user objects you have created
and what was the purpose of each?
Standard – Any single control can be placed in a standard user object
Custom – Many controls can be placed in a custom user object

6. What does OpenUserObject( ) do?
OpenUserObject( ) adds a user object to the specified window and makes all its properties and controls available to scripts.
windowname.OpenUserObject ( userobjectvar, userobjecttype {, x, y } )
This function is used when you want dynamically, at runtime place some user objects on a window. This function displays this user object, makes all its attributes available to scripts. You must open a user object before you can access the attributes of the user object. If you access the user object’s attributes before you open it, it will cause an execution error.

7. How can you dynamically place an User Object on the window?
By using functions : OpenUserObject( ), OpenUserObjectWithParm( )

8. When would you use a Standard User Object?
We use a standard UserObject to extend the standard set of predefined attributes, events, and functions or to encapsulate common controls into an object that can be reused without any additional work.

9. Can a standard visual User Object contain another User Object? No.

10. In what situations would you use a custom visual UserObject?
We use a visual custom UserObject when we frequently group controls in a Window and use the controls to perform the same processing.

11. What Events does the Custom Class have?
Constructor and Destructor

12. What events are available to a standard class User Object?
Constructor and Destructor

13. What events are available to a standard visual User Object?
It has all events that standard PowerBuilder control has it.

14. How can you instantiate non-visual object (class) in memory?
First we need to declare a variable of our User Object data type. We have to create an instance of our object in memory using command CREATE. Now we have access to the attributes and functions encapsulated in our User Object. When we don’t need this object anymore, we should Destroy it before we close an application to avoid memory leaking.
First we need to declare a variable having our object’s type:
uo_business_rules my_object
CREATE my_object - This will create an instance of our object in memory.
When we don’t need this object anymore, you should Destroy it to avoid memory leaking:
DESROY my_object or
We need to create (instantiate) a variable of the class UserObject type when we use the class
We create custom transaction object MY_TRANS
Then you have to declare and create this UserObject
MY_TRANS l_my_trans
l_my_trans = create MY_TRANS
Now we have access to the attributes and functions encapsulated in the UserObject.
We have to destroy MY_TRANS before we close the application

15. Once a standard user object is placed on a window, can you override its attributes? Yes, we can.

16. How can you override User Object’s function?
Using polymorphism: In the User Object that we put on the window (a descendant of original UserObject) we can declare a function with the same name as the function in an ancestor we want to override.

17. How many custom user events can you define and what triggers them?
In PB 4 we could have not more then 75 custom event ID’s that we use for each object. In PB5 we may have as many as we need but with no mapping to PB custom events, however the events can work as a functions. We trigger them manually by using functions in our scripts. New syntax to trigger the custom event is
object.event ue_cancel( )
object.event post ue_cancel( )

18. How is a custom visual UserObject different from a standard UserObject?
A custom visual user object is an object that has several controls that work as a unit.
A standard visual user object inherits its definition from a standard control. We modify the definition to make the control specific to our applications.

19. What events do you know for custom visual user objects?
Constructor - occurs after window’s open event or when a user object is dynamically placed in the window
Destructor -occurs after window’s Close event or when a user object is dynamically removed from the window
DragDrop When a dragged object is dropped on the user object
DragEnter - when a user object enters the user object etc.
Drag within
Drag leave
Other
RightButtonDown

20. How can you communicate between the window and user object in the window?
When we placed user object into the window we can write the script s for User Object event (conctructor, dectructor) but we cannot write the scripts for controls inside the user object. But we can use user object level functions or user events.

VARIABLES
1. What is a variable?
Variables are storage locations that hold values. The values can be entered by user, retrieved from a Database, calculated by the application. Variables must be declared before they are referenced in a script.

2. What does the scope determine?
The scope of a variable determines which scripts can access the variable to use or change its value. The scope of a variable determines the scripts in which the variable can be referenced.

3. What types of variables do you know?
Local—defined within a script for a control and can be accessed only within that script.
Instance—defined for an object (e.g., window or User Object) and can be accessed only with in an object.
Shared—defined for an object. All descendants of that object can access the variable (i.e. there is one variable with one value for the object and all of its descendants). Shared has a scope very similar of the instance but it also will be known for all instances of the object. Shared variable retains its value when instances of the object are closed and opened again. If the value of the shared variable is changed in one instance and then accessed in another, the second instance gets the new value.
Global variables can be accessed by any object and are known through the scope.

4. What is a local variable?
A local variable is declared in the script for a control or object that can only be referenced in that script. We use local variables when the value only needs to be known while the particular script is executing.

5. When do you use reserve word PARENT?
We can use it in the script for different events of controls. In this case it refers to window this control belongs to. If we use it in a script for a control in a custom user object, it refers to the user object. When we use it in a script for MenuItem it refers to the MenuItem on the level above.

6. What does the pronoun THIS refer to.?
It refers to the object or control we are writing script for.

7. What does the pronoun PARENT WINDOW refer to?
The pronoun PARENT WINDOW refer to the window that menu is associated with at the execution time.

8. When do you use instance variable?
You use an instance variable when you have data that have to be accessible in more then one script within the object, but don’t need to be global.

9. What access level for instance variable do you know?
PUBLIC - accessible for all scripts
PRIVATE - accessible in the scripts for events in the object for which the variable was declared
PROTECTED - accessible in the scripts for events in the object for which the variable was declared and its descendants.

10. What the difference between instance and shared variable?
An instance variable is initialized when the object is opened. When you close the object, it ceases to exist. When you open the object again, the instance variable is initialized again. But the Shared variable continues to exist when you close the object and if you open the object again the shared variable will have the value it had when you closed the object.

11. What does the qualified reference mean?
A qualified reference is a variable (or object) name made specific by prefixing a window or object name to the variable name. We qualify references to refer to a variable in a child within its parent. E.g.,
w_customers.sle_address
Qualifying variables or column name in the SQL statement also eliminate ambiguity.

12. What is a shared variable? An Instance variable? How do you use them?
A shared variable is a variable that belongs to an object definition and exists across all instances of the object. Shares variables retain their value when an object is closed and opened again. Shared variables are always private. They are accessible only in scripts for the object and for controls associated with the object. Shared variables can belong to the application object, a window, a user object, or a menu.
An instance variable is a variable that belongs to an object and is associated with an instance of that object (you can think of it as a property of the object). Instance variables have access keywords that determine whether scripts of other objects can access them. Instance variables can belong to the application object, a window, a user object, or a menu. (Difference: they have different scope. The value of the shared variable is the same in each instance of the object. Instance variables are associated with one instance of an object such as a window and each instance can have different values in the instance variable.)

1. What is Check-in, Check-out options on a Library Painter?
It is a Version control.
Check- in, Check-out are options on a Library painter, which control an access to Library entries. For example, when more then one programmer are working on a project, we want to prevent them from modifying a library entry at the same time. To control the access to library entries we 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( a test or development library), and sets the status of the entry to check out. As long as the status of an entry is checked out, we can change only to the working copy. If we try to open the original copy, PB displays a warning message. When we finish working with an entry that you checked out , we can Check-in entries on 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 delete the working copy from the library in which it is saved.

2. What is an access control system for developers?
Check-in, Check-out.

3. Did you use any Version Control systems such as PVCS?
No, we have used PowerBuilder’s own Check-in/Check-out feature in the Library painter.

WINDOW OBJECT

1. For the following window types, describe typical uses or provide examples of how they are used in commercially available products:
Main is initial window of an application.
Characteristics: operates independently of all other windows.
Child is subordinated to its parent window.
Characteristics: can exist only within parent; thus, automatically closed when its parent window is closed;
is never the active window;
appears as an icon within the parent window when it is minimised.
cropped when a user attempts to move it beyond its parent;
moves with its parent, since its position is always relative to the parent;
Uses: the main window for a customer displays information in textual form and a child window displays it graphically.
Response is application modal
Characteristics: cannot be minimized;
the user cannot go to other windows in the same application;
the user cannot go to other Windows applications;
remains the active window until the user responds.
Uses: displaying error or warning messages to the user;
requesting a critical item of information from the user before work can begin
(Select Window in the Window painter)
Popup is
Characteristics: has a parent window;
is never hidden behind its parent;
can display outside the parent window;
appears as an icon outside the parent window, at the bottom of the screen, when minimized;
minimizes within its parent, when its parent is minimized.
Uses: online help.
MDI is a style of application used to manage multiple documents of the same or different types within one.
Characteristics: Each of the document types in its own window, but all of the windows appear framed within a foundation window for the application.
MDI with Microhelp has the same behaviour as an MDI frame window without Microhelp, but it also permits the display of microhelp information in the status bar.
Characteristics: provides the Microhelp facility to deal with the limited number of words allowed in a Menu. In the status bar at the bottom of the frame we can display additional information about a MenuItem to help the user to understand what the MenuItem does.

2. What are the Types of Windows and how is each one used?
Main is used as a top-level, foundation window( or as a sheet in an MDI application)
Child is used as a subordinate window.
Pop-up is used to provide subordinate information and it is never covered by the parent window.
Response is used to obtain information from and provide information to the user.
MDI and MDI with microhelp is a window frame in which users can open multiple document windows (sheets).

3. What is a control?
Controls are objects that we place in a Window to allow the user to interact with the Application.


4. What kind of windows should be closed using the function CloseWithReturn( )?
Response Windows.

No comments:

Custom Search