Monday, August 30, 2010

powerbuilder interview question _ part 4

ENCAPSULATION

What is encapsulation?
Encapsulation means that the functionality of one object does not effect the functionality of another one.

1. What are benefits of using encapsulation? Give examples of encapsulation in PB.
Encapsulation gives us a way to hide and protect data inside an object to avoid a conflict with objects, all information is protected. To hide data, we use private and protected variables. For example, the code to make a CommandButton appear depressed is encapsulated into the CommandButton itself. Encapsulation is a method of encapsulating data inside an object, having function to manipulate the data and not allow access directly, only trough functions. Variables are private, functions to access those variables are public. Example: Let’s say you have a RadioButton on your window. To check it in the script, you can just state: rb_1.checked = true. If you want to use encapsulation, you would create a UO inherited from the RadioButton and complete with the user-object function which would have the script to check or uncheck this RadioButton and direct all the check/uncheck calls to this user-object function.

EVENTS

1. Explain ItemChanged and ItemError events?
ItemChanged event occurs when the item has changed the value in a DW control and all validation rules are passed successfully, in other words, all three conditions are met:
n Is anything changed?
n Is the data of correct data type?
n Does data pass validation rules?
ItemError event occurs when the item does not pass validation test for its column.

2. What is the OTHER event?
Any non-standard event is other event. The Other event occurs when a Windows event that is not a PB event occurs. For example, when the user presses the middle mouse button on a 3-button mouse.

3. If there is a problem with the DB during data retrieval :
n Which DW event will be triggered?
n Where will the error code be stored?
A DBError event will be triggered when a DB error occurs in a DW. The action codes for this event are: 0 - (Default) Display the error message.
1 - Do not display the error message.
The Error code will be stored in DBErrorCode, which PB 5 provides to us as an argument in the DBError Event.

4. What is the difference between an Open and Activate events?
The Open Event occurs after the window has been opened but before it is displayed.
The Activate event occurs just before the window becomes active. When the Activate event occurs, the first control in the tab order for the window gets focus, if there are no visible controls in the window, the window gets focus.

4a. What problem could be with Activate event?
Problem with Activate event is we cannot put FocusChanged commands such as MessageBox( ) in this event, because we will be in a loop.

5. What is CloseQuery event? When do you use it?
The CloseQuery event occurs before Close event when we remove the window from display (close it). We use CloseQuery event when we’d like to perform some processing or do some checking before user closes the window. If we do not want to allow the user to close the window, we set Return 1 else Return 0. Return 1 prevents the window from closing and must be the last statement in the script for the CloseQuery event. Be sure to set Return 0 when processing is complete so the window can be closed. To perform some processing or do some checking before you close the window set the value of Message.ReturnValue to 1 and then write a script for the CloseQuery event to perform the desired processing. The statement that sets message.ReturnValue to 1 to prevent the window from closing must be the last statement in the script for the CloseQuery event.

6. Which events do not “like” the MessageBox( ) function to be in their scripts?
All FOCUS events such as Vertical Scroll, Horizontal Scroll, Activate, LoseFocus event.

7. What functions cannot be used in the ItemChanged Event?
AcceptText( )
SetRow( )

8. What are Constructor and Destructor events?
Constructor event occurs in all draggable controls immediately before the Open event. Constructor event is also triggered when a user object is placed dynamically in a window. Destructor event occurs in all draggable controls immediately after Close event. Destructor event is also triggered when a user object is removed dynamically from the window.
9. What is Timer event ?
This is an event triggered by the Timer(n) function that occurs every n seconds after the function is called. E.g., we can display a message, beep, or open a window every n sec.

10. What do you use the SQL Preview event for?
You can use the SQL Preview event to display SQL statement right before its execution. It is useful for the debugging. In PowerBuilder 5: MessageBox(“SQL”, SQLSyntax)
SQL Preview event occurs immediately before Retrieve(), Update(), or ReselectRow () are executed. In PowerBuilder 4 to get the current SQL statement you could use either dw_1.Describe( ) or dw_1.GetSQLPreview( ) functions. For example:
string s_temp
s_temp = dw_1.Describe(“DataWindow.Table.Select”)
MessageBox(“My SQL”, “s_temp”)
Also, we could use SQL Preview event if we want to use Stored Procedures to perform Update in the Database.

11. When does SQL Preview event occur and what action codes does this event have?
The SQL Preview event has action codes that specify the action that takes place when the event occurs after an Update( ) function call. To set action code we use Return key word function.
The action codes are :
0 - (default) Continue;
1 - Stop processing;
2 - Skip this request and execute the next request.


12. What is the usage of the DBError Event?
We want to override the default error message. The DBError Event is used when a DB error occurs as a result of the operation performed by DataWindow Update( ) function.

13. When does PB trigger the DBError event?
Whenever there is an error following retrieval or update in the DW, for example, if we try to insert a row that does not have values for all columns that have been defined as not allowing NULL.
14. What events are triggered by Update( )?
SQL Preview
Update Start
Update End


15. How do you create your own custom event?
Why would you consider doing it altogether?

.EXE FILE

1. What is .EXE file?
.EXE file is a form of an application that can be executed outside of PB.

2. (true or false) You must have either .PBR or .PBD for every application. False

3. (true or false) You must have both .PBR and .PBD for every application. False

4.When do you need to use .PBD ? We use .PBD when:
n the number and size of the objects in our application would otherwise make a very large .EXE (1.2 to 1.5 megabytes).
n we need to share components among several applications.
n distribute application components selectively, for example, to upgrade an application or fix a bug.

5. When do you need to use a .PBR ?
We create .PBR if we have any dynamically assigned objects, bitmaps or icons and to reduce the number of files we need to distribute with the .EXE. We typically use a .PBR when we have scripts in our application in which we dynamically assign resources to attributes of objects or controls in the application. If we do not use a .PBR, we must distribute various .BMP, .RLE, .ICO files with the application. We must place in .PBD’s any objects that we reference dynamically in scripts in the application.

6. Why do we create PBR, PBD files?
We create .PBR if we have any dynamically assigned objects, bitmaps or icons to reduce the number of files we need to distribute with the .EXE. We have to create .PBD if we have more than one PBL. It allows us to break the application into smaller units that are easier to manage and makes the executable file smaller, and at execution time we can load any objects that are not contained in the application’s executable file. It makes sense to use PBD when our application is really large.

7. How many .PBDs can you have for one application ?
As many as we need and depending on available memory.

8. How many .PBRs can you have for one application ?
One
9. (true or false) If you have created a .PBD and a .PBR for an application, you must distribute the .EXE, the PBD, and the .PBR to the users.
True
10. What do you need to do before creating an .EXE file?
Before we create the .EXE for an application, we need to make sure that:
n the application is the current application;
n we have listed all of the necessary .PBLs in the library search path for the application;
n if we are using a .PBR, we have created it.

11. What do you have to distribute with your application to the end-user?
1 The .EXE File
2 The .DDL Files
3 Deployment kit ß .DLLs

12. What is .PBR file?
PBR file is an ASCII File in which we list resource names or DW object names that were referenced dynamically in the script.

12a. What are PBR, PBD files? How do you generate them?
.PBR file is a resource file that contains BMP files, icons or objects assigned dynamically in a script such as DW objects that have been used in our application. A .PBD file is PB dynamic library. It contains all compiled objects that the .PBL file has and is linked to the application at runtime. We generate them through the Project options of PB. If you use .PBR files you don’t need to distribute to user separately .EXE file and resource files - all these pictures, for example, will be included into .EXE file. To create .PBR file simply name the resources in a text file. In it, you can reference all these objects by including the name and the path of the .PBL and the object name. PB copies objects referenced in a .PBR into the .EXE file when the file is generated. PBD does not have any data source. It cannot be run alone and must be specified in the library search path. All .PBD’s must be specified in the library search path.

13. What are advantages of using .PBD s ?
PBD makes the size of your .EXE smaller, and objects that we put in PBDs will be loaded at runtime only when we need it.

14. What is the difference between DLL and PBD?
DLL is a file we compile using machine code in a 32-bit environment. With DLL files the system (our application) works faster. PBD is a file we compile using Pcode. When PB builds a dynamic library, it copies the compiled versions of all objects from the source library (PBL file) into dynamic library (PBD file).

15. How do you create a .PBR file?
Through any file editor or Shift F6.

16. How do you include a DataWindow in a .PBR file?
To include a DW in the list we have to write the name of the library (with extension .PBL) and name of the DataWindow object enclosed in the parenthesis. For example: Tutorial.pbl(d_emplist)
If the DataWindows library is not in the directory that will be current when the .EXE is built, we have to fully specify the full search path of a DataWindow object and put the DataWindow object name in parentheses: c:\pb\tutorial.pbl(d_emplist)

17. What is the recommended size of .PBL?
The recommended size is less than 800 KB and not more than 50-60 entries. Larger libraries could decrease the performance of the application. You should split large libraries.

18. How can you create in PB an executable that can receive parameters?
PowerBuilder has a function CommandParm( ) that retrieves the parameter string, if any, when the application is executed. For example:
Open Event string ls_command_line
ls_command_line = CommandParm( )
If the command line holds several parameters, you can use string functions Pos(), Left(), Right(), Mid(), etc., to separate the parameters.

19. What are DLL files and how can we access DLL functions from PB?
Dynamic Link Library is a store of executable code that an executable file (EXE) may dynamically link to, in order to make use of its functions. PB libraries may be compiled into DLLs to reduce the size of the primary EXE and allow the objects to be shared with other PB applications. Note: unlike standard DLLs, PB-generated DLLs may not be used from applications written in other languages. PB-generated DLLs may be accessed only from PB applications.

20. What is the difference between P-Code and Machine code?
Machine code is new and was introduced in PB5. P-code is compiled faster than the machine code but it creates .PBDs. Machine code creates DLLs
PB uses P-code.

21. What type of resources can we list in .PBR file?
Bitmaps, icons, cursors, sound wave files, etc.—all files that are not PB files.

22. What does the .EXE file contain?
The executable file contains code that application need to run a Windows application, compiled versions of application’s objects and resources that application uses.

23. Is it always necessary to create the PBR File to include resources in your EXE?
No, if resources were assigned in a painter they are automatically copied in your EXE but if they were referenced dynamically through the string variables, PB cannot identify them when compiling, and we have to include them into PBR file or distribute them separately.

24. Where can we create .EXE? We can create .EXE in the Project Painter.

25. What is the minimum that you must deliver for a PB application? (pick all)
- .EXE
- PBD
- .PBR
- .DLL
- resource file
- PB.INI
The PB.EXE must be on the client machine - true
If you have bitmaps or icons in your app., you must have a resource file - false

26. What do you need to do to distribute your application to the end-user?
The .EXE, any .PBDs, and the DB Development and Deployment Kit DLLs.
(We need to create an executable file (.EXE) of our application for distribution to users. To do so, we can choose from several options. Two of the options are:
• you can incorporate all of the PB objects, all bitmaps, all icons, etc. into one executable file. (Variation—incorporate all of the PB objects into the .EXE, and distribute it with separate files containing the bitmaps, icons, etc.) Additional options are: you can incorporate some of the PB objects and all of the bitmaps, icons, etc. into the .EXE file, but place the remaining PB objects in PB dynamic libraries (.PBD). (Variation: incorporate some of the PB objects into the .EXE; place the remaining PB objects in .PBDs; and distribute the .EXE and .PBDs with separate files containing the bitmaps, icons, etc. When distributing your applications, you must also distribute the PB runtime libraries (.DLLs).)
EXTERNAL FUNCTIONS

External functions are functions that are written in languages other than PowerScript and are stored in Dynamic Link Libraries (DLL’s).
A DLL is a file containing executable Windows code. This code can be called from a PB program even through it is written in another language such as C, Pascal or in any other language that supports the Pascal calling sequence for 16-bit and the standard calling sequence for 32-bit.

FUNCTION

1. What is a function?
A function is a pre-defined procedure that performs a specific task. A function is a set of some type PowerScript statements that performs some type of processing and return a value. Functions have two defining characteristics :
n all functions return a value
n all functions have a return type, i.e., the data type of the value that the function returns.

2. What is the difference between a function and a subroutine?
Subroutines do not return a values, and thus, they do not have a return type.
Subroutine is a set of some type PowerScript statements that performs some type of processing.

3. What can you do with the return value from a function?

4. Describe how object-level and global functions are stored.
Global functions are stored in .PBL as independent objects, not encapsulated within some other object.
Object-level functions are encapsulated within the object for which they are defined.

5. Which does PowerScript statement appear at least once in every function? Why ?
Return statement. Because every function returns a value, our code must include the Return statement.

6. If the statement “return ‘Complete’” appears in the code for a function, what conclusion can you draw about the function declaration?
The data type of the value that the function returns is String.

7. What is the difference between call by reference and call by value?
By reference means that the function has access to the value of original variable and can change it directly.
By value means that no matter what happens to variable in the function the value will be the same.
By reference means that receiving parameters get the address(memory location of the variable instead of value. This means when any new is assign to the parameters value, the value of original variable is changed. When we pass by value, we are passing the function a temporary local copy of the argument. The function can alter the value of the local copy within the function, but the value of the argument is not changed in the calling script for function.

8. Explain Function access types.
There are three function access types:
Public - lets the function be referenced externally using dot (.) notation
Private - restricts access to scripts within the object.
Protected - restricts access to scripts within the object or within objects inherited from this object.

11. What is the difference between private, protected & public functions?
• Private function you can only call in scripts for events in the object, in which the function was defined.
• Protected function you can call in scripts for events in the object in which the function was defined and its descendant.
• Public functions you can call in any place in the object

12. What is a user-defined function?
User-defined function is the collection of Pscript statements that perform some processing.

13. What kind of user-defined function do you know?
Global - that are accessible anywhere in the application Object level which are defined for the particular type of window menu or user object. These function may be accessible to other scripts or may be not.

14. How do you have to define the access for object level function if you want to make it accessible for scripts for other object?
It has to be defined as Public

15. What is the difference between Private and Protected Object level functions?
• Private function you can only call in scripts for events in the object, in which the function was defined.
• Protected function you can call in scripts for events in the object in which the function was defined and its descendant.

16. If function return the value what statement inside function do you have to use to assign value?
We have to use Return Statement and when we define a function we have to define the data type of returned value.


17. How could you pass argument to the function?
We can pass arg. By value and by reference When we pass by value we are passing to the function a temporary local copy of the argument and the value of argument in the calling script is not changed If we pass by reference the function has access to the original argument and can change it directly.

18. How do you look up functions for controls (for example, Listbox)
In the Help topic.

19. You need to process an array in a loop. Which function should you use if you don’t know array’s size (i.e. number of array elements)?
UpperBound()

20. What is the purpose of Yield function?

21. A function must be defined in the Function painter in order to be public? False

22. What is the difference between TriggerEvent and PostEvent?
TriggerEvent() stops the program and lets the program continue after it finishes.
PostEvent() stands in a queue and executes at the same time with the script. One difference between these events is timing. Postevent puts a custom window message at the back of the stack where it awaits its turn. TriggerEvent() program-matically causes code to be executed before the next message is processed. For example: cb_OK.TriggerEvent(Clicked!)

23. What is the difference between call by reference and call by value?
Calling by reference is a two-way argument passing: changes that the function makes to the argument value are passed back to the caller.
Calling by value is a one-way argument passing: the calling script passes a copy of the argument value into the function. Changes that the function makes to the argument value are not passed back to the caller.

2 comments:

Anonymous said...

superb....

Rajkumar said...

Interesting..;)

Custom Search