Powerbuilder Interview Questions Part 7

Powerbuilder Interview Questions Part 7

Question 1 What is the difference between SetTrans() and SetTransObject()?
Answer In simple terms, SetTrans() gives you no control on the transactions. It automatically connects to and disconnects from the database after each Retrieve() and Update() function. It is useful when the number of connections are limited, but, you can’t use this for multi-table update. On the other hand SetTransObject() gives you full control over the transactions. It is your responsibility to connect to and disconnect from the database and also, you need to issue COMMIT/ROLLBACK statements. This method is more efficient since there is no connect/disconnect overhead for each database operation.
Question 2 List all the buffers that a DataWindow control maintains.
Answer Primary!, Delete!, Filter!, Original!, and one buffer for the edit control.
Question 3 When the DataWindow is set to ReadOnly, What buffers PowerBuilder maintains for the DataWindow Control?
Answer PowerBuilder maintains all the four buffers, i.e., Primary!, Delete!, Filter!, Original!.
Question 4 How do you change the SQL Statement of a DataWindow at run-time?
Answer You can either use the Modify() or .Object notation to change the SQL statement of a DataWindow control. In the SQLPreview event, you can change it using SetSQLPreview(). Outside SQLPreview event, you can call SetSQLSelect().
Question 5 The new .Object notation syntax for the DataWindow control replaces the Modify() function. Explain.
Answer No, it doesn’t completely replace Modify() function. You can create objects such as rectangle, text objects in the DataWindow object using the CREATE statement in the Modify() function. This can’t be done with the .Object notation.
It is also not possible to refer to the data by column name dynamically, which can be done using Modify().
Question 6 Describe where you can’t use .Object notation for a DataWindow control instead of the Modify()?
Answer You can’t create objects in the DataWindow object dynamically using the .Object notation.
Question 7 How do you change the DataWindow object of a DataWindow control at run-time?
Answer DataWindow_Control_Name.DataObject = ‘New_DataWindow_Object_Name’
Question 8 What will happen if you pass extra retrieve arguments to the Retrieve() function for the DataWindow control?
Answer PowerBuilder ignores extra arguments.
Question 9 What will happen if you pass no arguments to the DataWindow’s Retrieve() function, when the DataWindow is expecting some arguments?
Answer PowerBuilder prompts you for the arguments at run-time.
Question 10 Can you use an array as an argument to the DataWindow’s Retrieve() function? If yes, How and where it is useful?
Answer Yes, you can use PowerBuilder array as an argument to the Retrieve() function. This is useful when you use IN clause in the SELECT statement of the DataWindow’s source.
Question 11 What would be the row status in the destination DataWindow when a row is copied from another DataWindow using RowsCopy() function?
Answer NewModified!
Question 12 I would like to allow the user to print selected rows. How it can be done?
Answer Have a hidden DataWindow control or a DataStore and assign the same DataWindow object that you are using to display on the window. Copy selected rows to the DataStore or the hidden DataWindow control (You can use RowsCopy() function) and print the DataStore or the hidden DataWindow control.
Question 13 What are the different statuses a row in a DataWindow can have?
Answer New!, NewModified!, DataModified!, NotModified!
Question 14 What are the different statuses a column in a DataWindow row can have?
Answer DataModified!, NotModified!
Question 15 Explain the use of AcceptText() function.
Answer This function applies the content of the edit control to the primary buffer after validating the data. PowerBuilder applies the edit control content to the Primary buffer whenever user press tab or click on another column within the DataWindow. if the user change the value of a single column and doesn’t press either tab or click on another column, PowerBuilder will not copy the changed data, that means the changes will not be applied in the database. Calling the AcceptText() function solves this problem. You can also specify to the Update() via argument to call AcceptText() internally before applying the changes to the database.
Question 16 When you update the DataWindow, what would be the each row status in the DataWindow when the update is successful?
Answer NotModified!
Question 17 You have deleted few rows, say 10 rows from a DataWindow, and update the DataWindow. How many rows would be available in the Deleted buffer after successful update?
Answer Zero Rows.
Question 18 Explain the advantages and disadvantages of calling AcceptText() function from the ItemChanged event of a DataWindow control.
Answer AcceptText() function shouldn’t be called from ItemChanged event. This is because, AcceptText() function triggers the ItemChanged event. That means, calling AcceptText() in the ItemChanged event will go into a loop. So, there are only disadvantages, no advantages. If you really need to call AcceptText() from ItemChanged event, create a user-defined event and post that event from the ItemChanged event.
Question 19 How do you change the default DataWindow error message title?
Answer Assign the application object’s ‘DataWindowMessageTitle’ attribute with the new DataWindow error box title.
Question 20 Assume, you have marked a field as ‘Required’. At run-time user tabs into that field and tabs out without entering a value in that field. Will PowerBuilder force the user for specifying a value? If not, how do you force the user for specifying the value?
Answer As long as the user do not change (In this context, do not enter the data) the column’s value, PowerBuilder do not force entering a value. The solution to this problem is, Call FindRequired() function before you update the DataWindow.
Question 21 Explain the DataWindow validation.
Answer PowerBuilder checks whether the data is changed or not by comparing the edit control value with primary buffer. It checks for the data type correctness, if the data is changed. Wrong data type will trigger ItemError event. When the data passes the data type checking, it executes the validation rule. Invalid data will trigger ItemError event. Correct data will trigger ItemChanged event. If the ItemChanged event returns zero, it will trigger ItemFocusChanged event, otherwise ItemError will be triggered. Depending on the ItemError event’s return value, either the cursor remains in the same column or will go to the next higher tab sequence’s field (In this case, ItemFocusChanged event will be triggered).
Question 22 When two DataWindow are being shared, what exactly would be shared and are there any restrictions?
Answer The presentation is not shared. The data (buffers including Delete! and Filter!) and the sort criteria is shared. There are few restrictions, which include, Crosstab DataWindow windows can’t share data, the client and the server in the distributed computing mechanism can’t share data. you can turn on the query mode only for the primary DataWindow. If a DataWindow is sharing data with a nested DataWindow, the handle to the nested DataWindow becomes invalid with each retrieval. So, GetChild() and ShareData() need to be called each time a nested DataWindow is retrieved.
Question 23 What is difference between ‘prompt for criteria’ and ‘Query Mode’?
Answer ‘Prompt For Criteria’ as the name says, prompts for the criteria–for all those columns that were marked–in its own display dialog box and ignores the DataWindow you have painted. It also ignores the tab sequence number, i.e., prompts even if the tab sequence is zero. ‘QueryMode’ is more flexible than the ‘Prompt for Criteria’, and it uses the DataWindow you have painted. It allows querying on all non-zero tab sequence columns in the DataWindow and you do not mark any column for this purpose. The former one promts for the values every time Retrieve() is called, where as the later one takes values only when you turn it on–by enabling QUERYMODE property.
Question 24 Say, you have a DataWindow which returns 10,000 rows. After retrieving few rows, say, 100 rows, you have decided not to retrieve the rest of the rows. Explain different methods of canceling the result set.
Answer There are two ways to accomplish this.
In the first method, you can call DBCancel() to cancel the query from a CommandButton Clicked event or in other event. However, once PowerBuilder starts retrieving the data, it will not give the control to the user till it completes retrieval. So, you need to put some code/comments in RetrieveRow event which will yield a little bit.
In the second method, you can just return 1 from the RetrieveRow event.
Question 25 Say, you have a DataWindow with two fields, emp_name, emp_address. Now, the focus is on the emp_name field. When the user press tab, what would be the return value of GetColumnName() from A.) ItemChanged and B.) ItemFocusChanged events?
Answer GetColumnName() returns ’emp_name’ in the ItemChanged event and ’emp_address’ in the ItemFocusChanged event.
Question 26 Explain the steps that are required to update a multiple-table DataWindow?
Answer In short, using the Modify function or .Object notation, you need to make one table updatable. You also need to set the primary keys for that table. Then update the DataWindow with FALSE argument for the reset option in the Update() function. After successful update, make the second table updatable and the first one not-updatable. Now call Update() function with TRUE for the reset option (If there are more than two tables, use the TRUE option to the last table to be updated). Commit after successful update and Rollback on unsuccessful update.
Question 27 What you have to do if you want the PowerBuilder to prompt for the sort criteria at run-time?
Answer Set the sort criteria to NULL value using the SetSort() function and call Sort() function.
Question 28 How many times PowerBuilder will retrieve data from the child DataWindow in the following situation. A DataWindow has a field with DDDW edit style. There are 1000 rows in the parent DataWindow.
Answer It retrieves only once. The thumb rule here is that, PowerBuilder retrieves data from the child DataWindow only when the child DataWindow do not have data in it.
Question 29 What command/function you use to select a row?
Answer SelectRow() function.
Question 30 If there are 10 rows selected in a DataWindow, and if you call DeleteRow() function, how many rows will be deleted? Explain.
Answer DeleteRow() has nothing to do with the row selection. It deletes only one row that you specify as the argument to it. If you want to delete all the selected rows, you need to call DeleteRow() in a loop for each selected row (You can find the selected row by calling GetSelectedRow() function).
Question 31 You have defined a composite DataWindow ‘d_master’ which has two DataWindows ‘d_emp_info’, ‘d_emp_paychecks’. ‘d_emp_info’ takes one argument and ‘d_emp_paychecks’ takes two arguments. ‘d_master’ is placed in ‘DataWindow_1’ DataWindow control. DataWindow_1.Retrieve( Arg1, Arg2, Arg3 ) will retrieve data without prompting. Do you agree? Explain.
Answer PowerBuilder prompts for the retrieval arguments. This is because, you can’t specify retrieval arguments in the Retrieve() function for the nested DataWindows. Instead, you need to set Nested_Arguments attribute using the Modify() function or .Object notation.
Question 32 What will happen when you pass a wrong argument to the Modify() function?
Answer Returns the error code, but doesn’t trigger any event such as DataWindow dbError or Error. However, doing the same using .OBJECT notation will generate error and trigger DataWindow Error event.
Question 33 What will happen when you use a wrong expression for a DataWindow in the .Object notation?
Answer Will trigger Error event of the DataWindow control.
Question 34 What is the difference between ‘Error’ and ‘dbError’ events in a DataWindow control?
Answer DbError event is fired when a database related error occurs. Error event at the DataWindow control level is triggered when a wrong expression is encountered in the .Object notation, or a OLE/OCX related error occurs. For database errors, if you do not write any code in DBError event, PowerBuilder displays the error in its own dialog box. In the later case, if you do not code to DataWindow ERROR event, it will fire Application SystemError event. If there is no code in that event, PowerBuilder displays the error message and terminates the application.
Question 35 Explain the following error: ‘Row(s) changed between retrieve and update’. Also explain how you will get rid of that error?
Answer PowerBuilder reports this error when some one/process updates the row after you retrieve it but before apply the changes. POWERBUILDER detects this type of error when you include the TimeStamp column in the DataWindow or use the ‘Key columns and Updatable columns’ in the WHERE criteria. We can’t avoid this error. The solution to this problem would be, reselect the row that caused the error and display it to the user with appropriate message and then update the database again. You can use ReSelectRow() function to get the latest values for the error row.
Question 36 What is concurrency control? How do you control it from the PowerBuilder?
Answer When multiple users are working on the same data, we have to make sure that we don’t corrupt others changes, either by updating their changes without looking at them or by any other means. When we apply changes to the database, we have to make sure that no body changed the data between your read and update. This can be controlled (not exactly controlling, but, we can detect) using the appropriate WHERE clause option in the update properties in the DataWindow painter.
Question 37 Explain different ways of generating a serial number for a column in a table. Explain ways in PowerBuilder and in the database. Which method you recommend?
Answer This has to be controlled from the database, not from the PowerBuilder. This is because, a unique serial number generated by a POWERBUILDER client may not be unique for other user or when it is put in the database. If the database supports auto incrementing (Different database vendors implement it in different ways, for ex: sybase implements using Identity column property, Watcom calls AutoIncrement, Oracle selects from a special table), then there is no problem. Otherwise, you can use a single row single column table to generate serial no. The method you choose might depend on the performance issues and number of expected inserts and other factors.
Question 38 I want to execute a stored procedure that is defined in the database, using the function call notation. What I need to do?
Answer Define a function that refers to the stored procedure, in the transaction object and start using the function. It is something like declaring an external function, however, you can’t declare a function for a stored procedure at any object other than a transaction object.
Question 39 Explain the steps involved in inserting your a layer between ‘transaction’ object and ‘SQLCA’.
Answer Create a standard class user object by inheriting from ‘Transaction’ object. Define the attributes and functions that you need. Now, ask the SQLCA to be of type YourTransactionObject instead of TRANSACTION object. This you can do in the application painter.
Question 40 Write the code to protect existing data from changes by the user in a DataWindow and allow adding new rows.
Answer DataWindow_1.Object.Column1.Protect = ‘1~tIf(IsRowNew(),0,1)’
Question 41 Explain the method you follow when you want to skip printing all pages that are divisible by 7 (seven)?
Answer Well, you can write code for the PrintPage event of a DataWindow control. Check whether the page number is divisible by seven, if so, then return 1.
Question 42 I want to use the value passed in the retrieval arguments in the DataWindow. What I need to do?
Answer If you are using PowerBuilder version 4.0 or above, you should be able to see the retrieval arguments under in the ‘Columns’ listbox in the ‘Expression’ dialog box. So, you can use it as if it is a column.
Question 43 The following situation triggers ‘SystemError’ event at the application object. Explain. You are trying to update a table on which you don’t have update privilege.
Answer This will not trigger the SystemError event, since it is a database & DataWindow related error. It triggers DataWindow DbError event. If there is no script for that event, PowerBuilder displays the error message in the default way.
Question 44 You got ‘Row(s) changed between retrieve and update’ error. Now, you want to select the latest value of that changed row. How you do that?
Answer Use ReSelectRow() function.
Question 45 In a DataWindow, there are few fields with validation rules, and few fields with script in the ItemChanged event. I want to display custom error message when data doesn’t go through the ItemChanged event, but want to display default error messages when the data doesn’t go through the validation rules. What should I do?
Answer Well, define an instance variable. Turn it one when you decide the data is invalid in the ItemChanged event. In the ItemError event, return appropriate return code depending on the instance variable value and reset the instance variable to it’s default value appropriately.
Question 46 I want to find out all the fields that doesn’t have values and have ‘Required’ attribute turned on. What should I do?
Answer Call FindRequired() function before you call Update() function.
Question 47 Can I store some data in the DataWindow? If yes, How?
Answer Select Rows/Data from the menu when you are in the DataWindow painter design mode and add data to the DataWindow and save the DataWindow. The data now is stored as part of the DataWindow definition.
Question 48 What I need to do if I want the child DataWindow shouldn’t retrieve the data automatically?
Answer Store an empty row in the child DataWindow. PowerBuilder do not retrieve data from the child DataWindow since it sees data inside it. You can store data in the child DataWindow, by selecting Rows/Data from the menu when you are in the DataWindow painter design mode.
Question 49 How many DataWindow can share the data from a DataWindow?
Answer There is no limitation on how many DataWindows can share data from the first primary DataWindow or from the secondary DataWindow that work as primary DataWindow for other DataWindows.
Question 50 What is the difference between a DataWindow and a DataStore object?
Answer DataStore is nothing but a DataWindow without interaction related events and functions. DataStore has less overhead compared to DataWindow since the DataStore object do not have interaction related overhead. You can use DataStore as a parameter to a remote object function/event in the distributed computing and OLE automation, where as DataWindow can not be used in those situations.
Question 51 Can a DataWindow share the data from a DataStore?
Answer Yes
Question 52 I have a table in which one column is of ‘LongBinary’ data type. Can I update this column using DataWindow? If yes, How?
Answer A regular DataWindow do not support BLOB data types such as ‘Long Binary’, Sybase’s Image & Text data type columns. You need to use ‘DATABASE BLOB’ object in the DataWindow object. You can update the database normally when you follow these steps.
Question 53 What is the difference between a ‘Computed Column’ and ‘Computed Field’?
Answer ‘Computed Column’ is a column that you define as part of the SELECT statement. These values are calculated by the database and sent to the PowerBuilder client. ‘Computed Field’s’ we define in the DataWindow bands and PowerBuilder calculates these values, not the database. Depending on your computing model ‘Fat Client’ or ‘Thin Client’ you can decide which one to use. If it is ‘Fat Client’ model, use ‘Computed Fields’, otherwise use ‘Computed Columns’.
Question 54 Can you change the value of a ‘Computed Field’ at run-time?
Answer No, you can’t the Computed field value directly. However, you can change the column value that are part of the Computed field expression, by that Computed field value will be changed automatically.
Question 55 What is a Dynamic DataWindow and how do you create a Dynamic DataWindow?
Answer Dynamic DataWindow is the DataWindow that is not painted at design-time, instead it is created at run-time. This is useful when you don’t know the exact columns that you need to include in the DataWindow at design time. You need to use SyntaxFromSQL() function and Create() function to create a DataWindow dynamically.
Question 56 How can I search a DataWindow?
Answer Use Find() function.
Question 57 In a DataWindow validation rule, how can I refer to the data that is entered by the user?
Answer Call GetText() function in the validation rule to get the data entered by the user. If you want to paint the same in the Database painter, you can use @name where name can be any text. PowerBuilder automatically converts @name to GetText() in the DataWindow validation rule when you paint a DataWindow that uses that column.
Question 58 Explain how ‘Retrieve Only Needed’ works.
Answer By default, PowerBuilder displays the first row on the screen when it completes retrieving all the result set. That means, if there is huge result set, user has to wait for long time to see the first row on the screen. If you turn on ‘RetrieveOnlyAsNeeded’ property, PowerBuilder retrieves only those rows that fit on one screen. That means, user will see the data quickly. When the user scrolls, PowerBuilder retrieves again (as many rows as required). This option might affect the database server performance also, since the result is queued at the database till PowerBuilder client completes retrieving.
Question 59 What should I do if I want to display rows as soon as they are retrieved from a DataWindow?
Answer Write code in the RetrieveRow event, at least a single line comment. And also set the ‘Async’ attribute in the DbParm property of the transaction object.
Question 60 Say, you have a DataWindow ‘d_emp’ which has a field ’emp’ with DDLB edit style. When you read the field value using GetItemxxxxxxxx() function, what value is returned, ‘Display Value’ or ‘Data Value’? What you need to do to get other value?
Answer Use the LookupDisplay() function.
Question 61 How do you handle variable length text fields in a DataWindow?
Answer Set the ‘AutoSizeHeight’ property in the detail band of the DataWindow when you are in the DataWindow painter design mode.
Question 62 How to retrieve multiple result set of a stored procedure in a single DataWindow?
Answer A DataWindow can retrieve only one result set at a time. If you want to retrieve other result sets also, you can change the result set number either by Modify() function or using .Object notation. When you change the result set, make sure the number of columns and data types match with the existing DataWindow definition.
Question 63 How to retrieve a particular result set of a stored procedure in a DataWindow?
Answer You need to suffix the result set number to the stored procedure name separated by semicolon.
Question 64 How to load a text file in a DataWindow?
Answer Well, you can use ImportFile() function.
Question 65 What is a CrossTab presentation Style DataWindow? What are the places you can use this type of DataWindow?
Answer Crosstab presentation style DataWindow allows to shorten the length of the report and display the data in a two-dimensional spreadsheet like report. One dimension displays in columns and the other as rows.
Question 66 How do you update a ‘Group’ presentation style DataWindow?
Answer A DataWindow with ‘Group’ presentation style can’t be updated.
Question 67 How do you update a ‘OLE’ presentation style DataWindow?
Answer OLE presentation style DataWindow is only for display, you can’t update that DataWindow.
Question 68 What are code tables and how you can use them in a DataWindow?
Answer Code tables are used for translation. Typical use of code table is to display long description about the data, say, ‘New York’ and store the abbreviation in the database, say, ‘NY’. You can use code tables in the DataWindow for the EditMask edit style only.
Question 69 What is the difference between a ‘column name’ and ‘database column name’. Can you change any of these at painting time? If yes, How?
Answer ‘Column Name’ is the name of the column in the DataWindow. You always refer to this name when you want to change the column attributes. You can change the column name in the DataWindow. The ‘Database column name’ is the name of the column in the database and you can’t change this name. Typically, this name is prefixed with the database and table and owner name. You can see both column and database column names by selecting ‘Rows/Columns’ in the DataWindow when you are in the DataWindow design mode.
Question 70 You have a DataWindow that has 100 rows. I want to append the rows to the existing rows when I retrieve next time in that DataWindow. Explain the required steps to do this.
Answer Return 2 in the RetrieveStart event of that DataWindow control.
Question 71 What is the event from which I can see the exact SQL statement that is being sent to the database by PowerBuilder?
Answer SQLPreview event of the DataWindow control.
Question 72 How to refer to a DataWindow column by the column number in the ‘Describe()’ and ‘Modify()’ functions.
Answer You need to prefix the column number with pound (#). For example, DataWindow_1.Modify( ‘#10.TabSequence=0’ ) sets the column number ten’s tab order to zero.
Question 73 How to update a DataWindow that has ‘Stored Procedure’ as the data source?
Answer Go to the update properites of the DataWindow by selecting Rows/Update properties from the menu when you are in the design mode in the DataWindow painter. Type the table name to update in the ‘Table’ prompt. Make sure the column names and data types are same.
Question 74 What are the uses of a DataWindow with ‘External’ data source?
Answer ‘External’ DataWindows are useful when you want to use the power of DataWindows, even though you are not retrieving the data from the database. Some of the features which would be more difficult to implement without using a DataWindow are, sorting, filtering, printing, exporting data into different formats, print previewing/zooming and so on.
Question 75 How many ‘OLE DATABASE’ columns you can use in one DataWindow?
Answer Well, you can paint as many OLE Database BLOBs as you wish in a DataWindow. However, the update is not going to take place when you place more than one OLE Database BLOB object in a DataWindow.
Question 76 What are different types of windows available in PowerBuilder?
Answer There are six different types of windows available in PowerBuilder. Those are Main, Popup, Child, Response, MDI Frame, MDI Frame with Microhelp.
Question 77 If I create a response window and open that window in an MDI frame using OpenSheet(), what will happen?
Answer When you open a window in a MDI frame using OpenSheet() or OpenSheetWithParm() functions, that window get the sheet properties, irrespective of the window type. That means, when you open the response window using one of those functions, the window will behave like any other sheet, i.e., gets maximize, minimize, close controls on the title bar.
Question 78 Explain how a popup window is different from a child window?
Answer Popup window can go beyond the parent window borders and Popup window is always on the top. On the other hand, the Child window can’t go beyond parent window borders. Child window is never considered as an Active window from the programming perceptive.
Question 79 What is MDI_1?
Answer MDI_1 control represents the ‘Client Area’ in a ‘MDI frame’ or ‘MDI frame with Microhelp’. That means, all the window area other than ‘Titlebar’, ‘Menu’, Microhelp statusbar’ is MDI_1. When you paint any object in the MDI window, you need to resize the client area programmatically by referencing MDI_1, otherwise, MDI_1 control size is not determined. That means, we can’t see any sheet that we open in the client area, unless we resize the MDI_1 control.
Question 80 What should I do if I want to paint a window control in a MDI Frame window?
Answer You need to resize the MDI_1 control. Window’s resize event is the good candidate to write the script for MDI_1 control re-sizing. You need to reduce the size of the MDI_1 control by the size of all the controls that you have placed in the window.
Question 81 Can I have multiple MDI frame windows in the same application?
Answer Well, technically, you can have multiple MDI windows in the same application. You can call Open() function twice, one for each MDI window. Please note that, the user might think that, two applications are running, since two different windows will appear with different menus.
Question 82 I need to declare an Instance variable for a DataWindow control ONLY, in a window. What should I do?
Answer When you declare an instance variable at a window, it is accessible to all controls in the window. First of all, you can’t declare an Instance/Shared variable for a specific control in a window. If you have the need of that, you need to create a user object of that specific control and declare instance/shared variables in the user object. Then place the user object in the window. In summary, a window control can’t have it’s own instance/shared variables, but the user object can (in the user object painter ONLY, not in Window Painter).
Question 83 Can I have a global and local variable with the same name?
Answer Yes, You can have global and local/instance variable with the same name.
Question 84 You have declared a global variable xyz and a local variable xyz in the clicked event of a CommandButton. When you refer to xyz in the CommandButton’s clicked event, which variable is referred? Global or Local?
Answer Well, when you refer to xyz variable, POWERBUILDER search for the variable in local, instance/shared, instance/shared at the ancestor, global order. That means, in this case, the local variable is referred. To refer to the global variable which has the same name of a local variable, you need to prefix double colon before the variable name.
Question 85 How a ‘Shared Variable’ is different from a ‘Instance Variable’?
Answer Well, the value of an instance variable in each instance is independent of other instances. Instance variables are created when the object is created and will be destroyed when the object is destroyed. On the other hand, the shared variable is shared between different instances of the variable. That means, changing the shared variable in one instance will affect other instances. The shared variable is created when the FIRST instance of the object is created and is destroyed when the application is closed. You can’t refer to an object’s shared variable when none of the instance is open, even though the shared variables exists in the memory.
Question 86 Tell me some situations where you need to use shared variables.
Answer One typical situation would be, counting the number of instances of a sheet. Another situation will be, you can use the shared variable to prevent the user updating the same record from multiple instances of the same window with different values.
Question 87 When a function argument is declared ‘By ReadOnly’, what you can do on that variable and what you can’t do?
Answer You can refer to that argument, you can change the value of the argument. But, you can’t assign another object to that object. For example, say, a DataWindow is passed as a ‘By ReadOnly’ argument. You can change the value of any column/row of that DataWindow, but you can’t say: arg_DataWindow = Another_DataWindow. In this case, you are assigning another object to this object. That means, you are asking to change the pointer to refer to the new object instead of the original object, which is not allowed when the argument is passed by ‘By ReadOnly’.
Question 88 What is the difference between passing a function argument ‘By Value’ and ‘By Reference’?
Answer When an argument is passed ‘By Value’, the changed value of the argument in the called function will not be available in the calling object. On the other hand, when the argument is passed ‘By Reference’, the changed value of the argument in the called object IS AVAILABLE in the calling object. In case of ‘By Value’, POWERBUILDER sends a copy of the object, where as a pointer is send when passed by ‘By Reference’.
Question 89 Can you declare CONSTANTS in PowerBuilder?
Answer From version 5.0 onwards, you can declare constants in POWERBUILDER. For example: CONSTANT APPEND_TO_ROWS 2. When you want to append to the existing rows in the DataWindow when you retrieve next time, write ‘return APPEND_TO_ROWS’ instead of ‘return 2’. Using constants you can make the code more readable and also more efficient (in some places).
Question 90 Explain the use of ANY data type.
Answer ANY data type was introduced in version 4.0. You can use this data type when you really not sure about the return value of function. For example, OLE 2.0 control and in OLE automation. You really don’t know what object/error code will be returned by the OLE client. Sometimes, those are compatible with POWERBUILDER data types. In those cases, you can use this variable to store the return value and CAST it to another data type before you operate on the value.
Question 91 How do you declare a function that returns nothing?
Answer Type ‘(None)’ without quotations in the ‘Return Value’ prompt when you are in the function painter.
Question 92 How to execute the ancestor event’s script from the descendant’s event?
Answer You can use CALL SUPER::EVENT_NAME syntax.
Question 93 What will happen when you TRIGGER a non-existing event?
Answer If you trigger a non-existing event using the old syntax, TriggerEvent(), nothing happens. In the new syntax, you can’t trigger a non-existing event unless you use DYNAMIC keyword. When you trigger the event dynamically, NULL value will be returned.
Question 94 What will happen when you TRIGGER an event that doesn’t have any script?
Answer Nothing will happen. You are not allowed to capture the return value of an event which returns nothing. NULL value is returned when you trigger an event which has no script.
Question 95 What is the difference between TriggerEvent() and PostEvent()?
Answer TriggerEvent() executes the specified event’s script right away. PostEvent() posts the requests in the operating system’s queue. This doesn’t mean the posted event’s script will be executed after completing the current script execution. It might execute right away also, it depends on how many requests are in the Operations system’s message queue.
Question 96 What is the difference between TriggerEvent() and Send()?
Answer TriggerEvent() JUST executes the specified event’s script, but, it do not really trigger the event. For example, triggering the window’s ‘Close’ event will execute the script written for that event, but, will not close the window. If you use Send() function, it does both, i.e., executes the script and closes the window also.
Question 97 How PowerBuilder executes events? Bottom-to-Top or Top-to-Bottom?
Answer Top-to-Bottom
Question 98 In the inheritence hirerachy, How PowerBuilder search for a function? Top-to-Bottom or Bottom-to-Top?
Answer Bottom-to-Top
Question 99 Explain different levels of attribute/method protection available in PowerBuilder?
Answer Public, Protected, Private, PrivateRead, PrivateWrite, ProtectedRead, ProtectedWrite
Question 100 How do you pass a value to a window at opening time?
Answer Use either OpenWithParm() or OpenSheetWithParm() function depending on whether you are trying to open a window as a window or a sheet.
Question 101 Explain what a ‘Message’ object is and How it is useful in the programming?
Answer ‘Message’ object contains the messages that are sent by the operating system and sent by the POWERBUILDER scripts. It always contains only one message, that is the latest one. When you use OpenWithParm(), OpenSheetWithParm(), OpenUserObjectWithParm(), those parameters are placed in the ‘Message’ object and you can access those parameters in the opening object from the ‘Message’ object. Changing the values of the ‘Message’ object affects the event execution. For example, changing the ‘ReturnValue’ of the Message object in the window’s CloseQuery event to 1 will stop the window being closed.
Question 102 What is the difference between ‘Close’ and ‘CloseQuery’ event?
Answer POWERBUILDER triggers ‘CloseQuery’ event before it triggers ‘Close’ event. If ‘CloseQuery’ event’s script is not executed successfully (in terms of return value), ‘Close’ event will never trigger.
Question 103 Explain typical scripting that you do in the ‘CloseQuery’ event?
Answer Typical scripting would be, checking for unsaved work and prompting the user for the same and take action depending on the user’s response.
Question 104 What should I do if I want to use ‘-‘ (hyphen) in identifiers in PowerScript?
Answer Add ‘DashesInIdentifiers=1’ without quotations to the [POWERBUILDER] section in the POWERBUILDER.INI file.
Question 105 Explain different debugging mechanisms in PowerBuilder.
Answer First mechanism would be obviously the debug painter. You can also use TRACE flag to log all the ODBC calls, /PBDEBUG to log the POWERBUILDER script execution.
Question 106 What should I do if I want to call a Windows SDK API?
Answer You need to declare the Windows SDK API as an external function either locally or globally depending on your need. Then only you can refer to that function in PowerScript. If you have the same function name in PowerScript also, you can alias the external function in the declaration.
Question 107 List three PowerBuilder pronouns that we use to reduce hard-coding.
Question 108 How ‘Parent’ is different from ‘ParentWindow’?
Answer ‘Parent’ pronoun is used to refer to the object in which the current object is. For example, referring to ‘Parent’ in a CommandButton’s script will refer to the window in which the CommandButton is placed. This is used in window control’s scripts and functions. On the other hand, ‘ParentWindow’ is used to refer to the window for which the current menu is attached.
Question 109 What should I do if I want to display an User Object at specific location in a window dynamically?
Answer You can specify the X and Y co-ordinates in the OpenUserObject() and OpenUserObjectWithParm() functions.
Question 110 Did you ever use Handle()? Where and How?
Answer Handle() function gives the handle number of a given window. In simple terms, it is the number that identifies a window uniquely. You can use this function to check whether a particular window is open or not. Especially useful when you want to check whether another instance of the same application is running or not. You can use this function along with FindWindow() Windows API call.
Question 111 I want to find out whether the PowerBuilder application is still connected to the database or not. What should I do in the PowerScript?
Answer Use DbHandle() function.
Question 112 I have a window which has a menu associated with. For some reason, I deleted the menu. Now, I am getting error when I try to open the window. What should I do?
Answer If you remember the menu name, just create a dummy menu with the previous menu name. Now you should be able to open the window. Then, you can de-reference the menu from the window. If you don’t remember the menu name, export the window and look in the exported file for the menu name. If you know really, you can edit the exported file and import it back otherwise, just note down the menu name and follow the first method.
Question 113 There is a ancestor window ‘w_1’ with one SingleLineEdit control ‘sle_1’. Now, I created another window ‘w_2’ by inheriting from the ‘w_1’ window. In ‘w_2’ I changed the window background color to Pink. Then, I went back to ‘w_1’ and changed the window background color to Blue and ‘sle_1’ background color to Red. What color changes will reflect in ‘w-2’ window?
Answer The thumb rule is that, if you have done any changes to a specific attribute in the descendent, then any further changes to the same attribute in the ancestor WILL NOT affect in the descendent. That means, since you have changed the window background color in the descendent, ancestor’s background color change do not affect the descendent. You haven’t changed the background color for the sle_1 in the descendent, So, the background color change for the sle_1 in the ancestor will reflect in the descendent also.
Question 114 What are PowerBuilder system tables and how they are useful for a PowerBuilder programmer?
Answer There are five POWERBUILDER system tables, ‘PBCatCol’, ‘PBCatEdt’, ‘PBCatFmt’, ‘PBCattbl’, ‘PBCatVld’. These tables store all the table, column specific information and POWERBUILDER extended attributes. These tables are created in the connected database by POWERBUILDER when the first user connects for the first time. These tables allow you defining extended attributes such as validation rule, edit style, display style, etc.. Once you create the extended attributes, these values are by default used when you create a DataWindow, which will reduce a lot of work and makes dws more consistent.
Question 115 How do you synchronize Database tables with the PowerBuilder catalog?
Answer In the database painter, there is an option to synchronize POWERBUILDER system tables with actual table/column information.
Question 116 What is a validation rule? How PowerBuilder validation rule is different from the Database (validation) rules?
Answer Validation rule specifies valid values for a specific column. It allows you to specify different valid values depending on the content of other columns. Validation rules defined in POWERBUILDER are used only POWERBUILDER clients. If another application connects to the database from Excel or Delphi, the database is not going to validate the data, since, the validation rule is not defined in the database. Please note that, the validation is done by POWERBUILDER not by the connected database. On the other hand, if you define the validation rule in the database, database will validate the value irrespective of the client type. In this case the validation is done by the connected database not by PowerBuilder.
Question 117 Explain different ways of executing a database stored procedure from PowerBuilder.
Answer You can source the stored procedure to a DataWindow. You can also execute in the embedded and dynamic SQL. With version 5.0, you can declare a function for the stored procedure in the transaction object and execute the stored procedure as if you are executing a function.
Question 118 What is a proxy object and what is a remote object?
Answer Proxy object represents the remote object in the distributed computing. Whenever you create a custom class user object, you can specify the proxy name. POWERBUILDER automatically saves the proxy object whenever you save user object. You place the actual user object in the server application and keep the proxy object in the client application. Before you act on the proxy object, you need to call SetConnect() function to connect to the server object.
Question 119 What is DDE?
Answer DDE means Dynamic Data Exchange. This technology allows two different applications talk to each other under MS-Windows environment and exchange data between them.
Question 120 List few DDE related events.
Answer ‘HotLinkAlarm’, ‘RemoteExec’, ‘RemoteHotlinkStart’, ‘RemoteHotlinkStop’, ‘RemoteRequest’, ‘RemoteSend’.
Question 121 What is the PowerBuilder object that has DDE related events?
Answer Window
Question 122 What is difference between ‘Cold Link’ and ‘Hot Link’?
Answer In case of Hot link, the changed data is sent to the client automatically by the server. In case of ‘Cold Link’, the changed data is available to the DDE client only when it requests for that.
Question 123 What is the difference between ‘In-Place editing’ and ‘Off-site editing’?
Answer In case of ‘Off-Site Editing’, the OLE Server allows you editing in a separate window other than the OLE client application window. In case of ‘In-Place Editing’, the OLE server gets activated in the OLE Client application window and all the menu options will change accordingly. In this model, user feels that he is working in a single application even though he is using a different application.
Question 124 What is OCX control? Explain the required steps involved in CREATING an OCX control in PowerBuilder?
Answer OCX is a OLE control which implements the component based architecture. You can use OCX control in any application that supports OLE 2.0. This increases the object reusability. You can use the OCX control in POWERBUILDER, but, you can’t create a OCX control in POWERBUILDER in version 5.0.
Question 125 What is the difference between ‘Embedding’ and ‘Linking’ in the OLE context?
Answer When you embed an object, the embedded object will be saved as part of the OLE container object. That means, any future changes to the actual object will not reflect in the embedded object. This also increases the storage requirement. Embedded object allows In-Place editing. In case of ‘Linking’, the original object resides where it was and a link information is stored in the OLE container object. That means, any future changes to the actual object will automatically reflect in the OLE container object. Linked objects are always invoked for editing off-site.
Question 126 What is ‘AutoInstantiate’ and where it is useful?
Answer The user object that has ‘AutoInstantiate’ attribute turned on, will automatically creates an instance of that object whenever the object is declared. You need to use the CREATE statement to create the object after declaration when this property is not set. This attributes is available only for custom class user objects.
Question 127 What are the different places you can use OCX control in PowerBuilder?
Answer You can use OCX control in a window, in a user object and in a DataWindow.
Question 128 Several times I heard ‘Registry’ in the technical meetings. What exactly ‘Registry’ is?
Answer Registry is a MS-Windows database that contains information about each application. The application populates the information about it self using Windows API calls. Previously, application specific information such as application preferences, settings are stored in .INI file which is an ASCII file. Even though there was registry under MS-Windows 3.x, it wasn’t really used by most of the applications and it was just used to store DDE and OLE specific information. The data is stored in the registry in the directory like hierarchy format.
Question 129 Explain the steps required to create a C++ user object in PowerBuilder?
Answer Basically, you need to invoke the user object painter for C++ user object type. You need to declare any instance/shared variables and functions. While declaring functions, you just declare the function interface, not the function code. You need to write the actual code for functions in the C++ Editor which comes with POWERBUILDER. When you save the user object. POWERBUILDER automatically save the user object as a DLL and you need to deploy this DLL along with your application.
Question 130 We have migrated all our applications from Visual Basic to PowerBuilder. I would like to use those VBX controls, instead of re-coding in PowerBuilder. Is it possible? If Yes, are there any restrictions?
Answer If you are using POWERBUILDER versions prior to 5.0, you can create a user object of type VBX and reuse your VBX control. The limitation is that, only Visual Basic v1.0 specific VBXes are supported by POWERBUILDER. In POWERBUILDER 5.0, you can’t use VBX any more. Actually, it would be better stop using VBX and migrate to OCX which allows deploying your applications in 32-bit environment.
Question 131 The OCX control I planned to use has a ‘Clicked’ event. The OLE 2.0 control in PowerBuilder already has ‘Clicked’ event. What should I do?
Answer When you are in the design mode, delete the duplicate events by selecting ‘Declare/User Events’ from the menu. This will solve the run-time problems.

Good Luck!


About The Author

Leave A Comment?