powerbuilder_ Powerscript

Share Embed Donate


Short Description

Download powerbuilder_ Powerscript...

Description

powerbuilder: Powerscript

http://belajar-powerbuilder.blogspot.com/search/label/Powerscript

Berbagi

Laporkan Penyalahgunaan

Blog Berikut»

Buat Blog

Masuk

P O W ER B U I L D E R  A L L A B O U T P R O G R A M M I N G

CATEGORIES

DOWNLOAD RINGTONES,  W A L L P A P E R , G A M E S

AJAX (4) Android (4) APACHE (1) Bind DNS (1) CENTOS (5) Database (6) datawindow (27) Graph (2) Iphone (1) Java (2) JQuery (1) MySQL (9) Netbeans (3) Oracle (6) PHP (18) powerbuider 11.2 (1) powerbuilder (34) Powerscript (38) recursive function (1) SEO (4) SQL (22) Squid Proxy (1) treeview (1) VB.NET (6) VirtualBox (1) VS FTP (1) WIN 32 API (12)

asikaja.com RABU, 30 JULI 2008

Auto Global Variables

SEARCH

OO purists say you should not have any global variables but as we all know you do not always have time to be pure. In most applications you normally have a few global declarations, usually some kind of an application manager or maybe an object request broker.

BOOKMARK 

Well if you export a PowerBuilder object an look at its source near the top of the code is a line that looks like: global type u_ken from userobject

 A R S I P B L O G

Mei 2012 (10) Which means that all objects created within the PowerBuilder painters have

April 2012 (9)

an automatic global variable of their type and name created. This is used

Maret 2012 (11)

by PowerBuilder to solve the references within your source objects but we can take advantage of this undocumented feature and just create an object of the correct type into this automatic global variable:

Februari 2012 (11) Januari 2012 (4) Desember 2011 (2)

u_ken = CREATE u_ken If you stop and think about it, PowerBuilder uses these variables itself at run time. For example when you say Open( w_mywindow ) the window

Maret 2010 (1) Januari 2010 (1) Oktober 2009 (1)

w_mywindow is instantaited and its handle it stored in the global variable

Agustus 2009 (1)

w_mywindow of type w_mywindow. This is how PowerBuilder knows the

Mei 2009 (3)

window is already open when you try to open it again using the same name, it also why you have to use a more complicated version of the Open command to open multiple copies, as there is only one global variable

November 2008 (3) Oktober 2008 (6)

called w_mywindow in the application.

September 2008 (1)

D I P O S K A N O L E H V I R T U E DI 0 8 : 3 1

Agustus 2008 (17)

L A B E L : POWERSCRIPT

Juli 2008 (41) Juni 2008 (72)

Large Random Numbers in powerbuilder

Mei 2008 (33)

 /////////////////////////////////////////////////  ///////////////////////// ///////////////////////////////////////////////// /////////////////////////  // Function: Function: f_BigRand f_BigRand  //

MENGENAI SAYA  VIRT UE

 // Description: Description:  // This function function uses uses 2 calls calls to Rand to generate generate Random Random numbers numbers for large

LIHAT PROFIL LENGKAPKU

 // ranges. ranges. It breaks breaks the range range into blocks of 32767 (max (max range range for  // RAND function) function)  // The limit limit of the function function is 32767 blocks of 32767.  // It calls RAND to first first determine determine which which block, then calls calls RAND again again to  // determine determine the number number in the  // selected selected block. To ensure even probability probability over over the range range where where  // there are multiple multiple blocks, blocks,  // the same same sub range range is used for each block. block.  //  // Argument Argument al_range al_range  // The upper upper limit limit of the range range of random random numbers numbers you want returned. returned.  // The lower lower limit is always always 1. The maximum maximum value value for the the argument argument is  // 1,073,676, 1,073,676,289 289 or 32767*3 32767*32767. 2767.  //  // Returns Returns  // A random random number number in the the range 1 to al_range al_range inclusive. inclusive.  // Or 0 if max max range range exceeded. exceeded.  //  // Author: David Dennis Dennis  /////////////////////////////////////////////////  ///////////////////////// ///////////////////////////////////////////////// /////////////////////////  //  // Revision History

1 d i 15

06/08/2012 11 16

powerbuilder: Powerscript

http://belajar-powerbuilder.blogspot.com/search/label/Powerscript

 //  // ---------------------------------------------------------------------- // VERSION CHANGE ID WHO WHEN WHAT/WHY  // ---------------------------------------------------------------------- // 6.30 8/4/00 Initial version.  ////////////////////////////////////////////////////////////////////////// Long ll_Offset, ll_Return Integer li_Range, li_Blocks  // Block size is set to 32767 as this is the maximum range  // the RAND function can handle Integer li_BlockSize = 32767 IF al_range > 1073676289 THEN  //Range is too big Return 0 END IF  //Determine The number of blocks li_Blocks = Truncate(al_range/li_BlockSize,0)  //Add an extra block to accommodate any remainder IF Mod(al_range, li_BlockSize) > 0 THEN li_Blocks = li_Blocks + 1 END IF  // Improve efficiency for ranges less than Block Size  // where there is only one block IF al_range < li_BlockSize THEN li_Range = al_range ELSE li_Range = li_BlockSize END IF ll_Return = 0  // Loop until the value is in range.  // If the value is not in range, calculate the  // Offset again to ensure even probability DO UNTIL (ll_Return > 0) And (ll_Return 0 AND ll_MatchingItem = 0 AND li_level >= li_ChildLevel  // only do comparison if we're at the correct level (i.e. immediate child  // or checking all levels) IF li_Level = li_ChildLevel OR ab_AllDescendants THEN  // Check if this item matches using pfc_u_tv function IF Trigger Event pfc_searchcompare(ll_Handle, as_Attribute, aa_Target, &  ab_RespectCase, ab_FullCompare) Then ll_MatchingItem = ll_Handle END IF END IF  // Get the next Tree Item, going deeper into tree if the caller requested it IF ab_AllDescendants THEN ll_Handle = FindItem(NextVisibleTreeItem!, ll_Handle) ELSE ll_Handle = FindItem(NextTreeItem!, ll_Handle) END IF IF ll_Handle > 0 THEN IF This.GetItem(ll_Handle, ltvi_Item) = -1 Then Return -1 li_level = ltvi_Item.Level END IF LOOP Return ll_MatchingItem This supporting function gets the first expanded child for a specified TreeView item, if any. Function: GetFirstExpandedChild (supports f_FindChild)

7 d i 15

06/08/2012 11 16

powerbuilder: Powerscript

http://belajar-powerbuilder.blogspot.com/search/label/Powerscript

Long ll_Handle TreeViewItem ltvi_Item  // if whole tree is being searched, start looking from the first tree item IF al_Parent = 0 THEN ll_Handle = FindItem(RootTreeItem!, 0) ELSE IF This.GetItem(al_Parent, ltvi_Item) = -1 Then Return -1 // error getting TVI  // If the specified tree item is not expanded, it will have no expanded children IF ltvi_Item.Expanded = False THEN ll_Handle = 0 // return not found ELSE  // it's expanded, so get handle to first child ll_Handle = FindItem(ChildTreeItem!, al_Parent) END IF END IF Return ll_Handle D I P O S K A N O L E H V I R T U E DI 0 9 : 4 9

TIDAK ADA KOMENTAR:

L I N K K E P O ST I N G I N I

L A B E L : POWERSCRIPT

SENIN, 16 JUNI 2008

The Invisible MessageBox in Powerbuilder The MessageBox may not display in the example below: SELECT cust_name INTO :ls_CustName FROM Customer WHERE cust_id = :ls_custid; MessageBox( "Warning!", "Customer: " + ls_CustName + &  " does not have sufficient credit." ) If the customer is not found or if the customer name is Null, then no MessageBox will display. The reason: MessageBox displays nothing if an input parameter is Null (or evaluates to Null when concatenated). Having no MessageBox display could clearly result in both logic and business problems. Since the problem is essentially hidden, it might not be discovered for a long time. The solution: if you are using a framework (like PFC) and you should consistently use its Message (or "Error") service which should handle such a situation. Otherwise, create your own function like f_MessageBox (see sample code). As shown in the sample code, f_MessageBox explicitly checks for Null input. It can display an error and/or log the error when it receives Null input. D I P O S K A N O L E H V I R T U E DI 1 0 : 1 3

TIDAK ADA KOMENTAR:

L I N K K E P O ST I N G I N I

L A B E L : POWERSCRIPT

Setting Focus to the TabPage with the Control in powerbuilder A common problem when using Tab objects is that you can set focus to a control (e.g. a DataWindow) on the tab but that control is not actually visible, since another Tab Page is selected. This may happen because another TabPage (e.g. TabPage 2) has focus when the save process starts and the DW on this Tabpage (e.g. TabPage 3) has an ItemChanged Error message to display. It is useful to create a general-purpose function that determines whether the control is on a Tab object and, if it is, sets focus to the Tab Page where the control is placed. The general-purpose function below was placed on the ancestor DataWindow object (u_dw in PFC) but it could be placed on any ancestor object.

8 d i 15

06/08/2012 11 16

powerbuilder: Powerscript

http://belajar-powerbuilder.blogspot.com/search/label/Powerscript

Function Name: f_MakeTabPageCurrent Purpose: This function determines whether this control is on a Tab Object. If so, it makes the tab page that has this control current. If this object is not on a tabpage, then nothing happens. Parameters: None Returns: Long >0 Index of tabpage where object was placed (and focus was set) 0 the object was not placed on a tab object. -1 Error encountered integer li_Index boolean lb_TabParentFound = False boolean lb_TabPageFound = False long ll_RetCode u_tab lu_tab // u_tab is a standard visual user object of type "tab" powerobject lo_CurrentParent, lo_CurrentChild, lo_TabPage  // Loop through control hierarchy until a Tab control or Window is found lo_CurrentParent = This.GetParent() DO WHILE (NOT lb_TabParentFound) AND (lo_CurrentParent.TypeOf() Window!)  // we found tab control IF lo_CurrentParent.TypeOf() = Tab! THEN lu_tab = lo_CurrentParent // keep handle to Tab control lb_TabParentFound = True ELSE  // if we're not at window yet, keep looking for a window or tab control IF lo_CurrentParent.TypeOf() Window! THEN lo_CurrentChild = lo_CurrentParent // keep handle for the Child object lo_CurrentParent = lo_CurrentParent.GetParent() // Get next parent END IF END IF LOOP  // If a tab parent was found for this control, then make  // the tab page containing our control current IF lb_TabParentFound THEN lo_TabPage = lo_CurrentChild // tabpage was second last object looked at li_Index = UpperBound(lu_Tab.Control[])  // Loop through child tabpages of Tab control looking for the tabpage DO WHILE NOT lb_TabPageFound and (li_Index > 0) IF lu_Tab.Control[li_Index] = lo_TabPage THEN  // tab page found ... select it lu_tab.SelectTab(li_Index) lb_TabPageFound = True ELSE li_Index = li_Index - 1 END IF LOOP IF lb_TabPageFound THEN ll_RetCode = li_Index ELSE  // TabPage not found -- maybe not in control array? (PB5 possibility) ll_RetCode = -1 END IF ELSE ll_RetCode = 0 END IF Return ll_RetCode D I P O S K A N O L E H V I R T U E DI 1 0 : 1 2

TIDAK ADA KOMENTAR:

L I N K K E P O ST I N G I N I

L A B E L : POWERSCRIPT

MINGGU, 15 JUNI 2008

How to store your error messages with powerbuilder

9 d i 15

06/08/2012 11 16

powerbuilder: Powerscript

http://belajar-powerbuilder.blogspot.com/search/label/Powerscript

If you have an application which uses the PFC error message service (n_cst_error), you might have given some thought to distributing your application with the messages stored in a table. At first, the error message table looked very attractive. And it is, for most situations, especially those which access a central database. However, if your application is deployed to many different locations and each location contains a database, the table approach can become a nightmare. As with many technical problems, a alternative approach came to me right after implementing a valid solution. At present, I'm storing this data within a database table which is immediately cached as soon as the application starts. I'm going to change the approach so that the datawindow contains the data all the time via the Rows/Data method. The specific problem I'm trying to solve is the updating of the messages table as used by the PFC error service. At present, the options provided with PFC are limited to sourcing the messages from a file or from the database. I want a third source: the datawindow, unretrieved. I'm going to extend the error object via the PFE and add a third version of  of_SetPredefinedSource. When a new message is to be added to the list, I'll do it directly within the datawindow painter via Rows/Data. If I was continue maintaining the data within the table, then I would need to distribute updates to that table when new messages were added. Somehow these would be loaded into the database if they hadn't already been loaded. I think the PFC extension approach leaves less room for error. The application will always have the error messages associated with that version of the application. D I P O S K A N O L E H V I R T U E DI 0 8 : 3 5

TIDAK ADA KOMENTAR:

L I N K K E P O ST I N G I N I

L A B E L : POWERSCRIPT

Using the Resize and Preference service together in powerbuilder The resize service (n_cst_resize) is useful for windows which contain controls which can be resized. The preference service (n_cst_preferences) is great for users. It allows windows to remember their last position and size. However, unless you use these services in the correct order, you can get into strife. For example, if you don't set the resize service and register your controls before the ancestor's open script completes, you may have wind up with controls that have not been resized properly. Below are two screens. The first has not resized correctly but the second one has correctly resized. The difference between the two windows is the following script in the pfc_preopen event. This script will be executed before the open event of pfc_w_master which is where the preferences are reset. You'll note that of_SetOrigSize() is commented out. I've never actually found a situation where this is needed or useful. But that doesn't mean it isn't useful. Somewhere...out there. this.of_SetResize(TRUE)  //this.inv_Resize.of_SetOrigSize(this.width, this.height) this.inv_Resize.of_Register(dw_1, "ScaleToRight&Bottom")

resize1.gif (49186 bytes) Incorrect resizing resize2.gif (36495 bytes) Correct resizing D I P O S K A N O L E H V I R T U E DI 0 8 : 3 2

TIDAK ADA KOMENTAR:

L I N K K E P O ST I N G I N I

L A B E L : POWERSCRIPT

JUMAT, 13 JUNI 2008

ItemChanged Event in powerbuilder This event occurs whenever the data is changed and the current field looses its focus (clicking on other field or other control, pressing tab, etc.). Use this event to validate the data and trigger ItemError event, whenever there is an error in the data. This

10 d i 15

06/08/2012 11 16

powerbuilder: Powerscript

http://belajar-powerbuilder.blogspot.com/search/label/Powerscript

is one of the frequently used events in the DataWindow control. This event gives access to the old data (which is retrieved from the database), as well as the new data (the data changed by the user). Let's write some validation code in the event. For example, let's display an error message, if the user enters an existing product_no, while entering a new record. Actually, database gives an error message if duplicate product_no is entered, because, product_no is a primary key for the product_master table. The reason we would like to validate here is, to display the error message as soon as the user enters a duplicate product_no, instead of waiting till the whole record is entered and sent to the database. Which means that we need to check for the existence of the product_no, as soon as the user presses the tab key in the new record. This check can be done by using embedded SQL or with a hidden DataWindow control. We didn't teach embedded SQL yet, so, let's go with the second method. Place a new DataWindow control in the window and name it as dw_product_check. Go to the properties dialog box for this DataWindow control and assign d_display_product DataWindow object to this control. In case you don't remember, d_display_product takes an argument product_no and brings the data for the given product_no. If you don't get any results for the given product_no, it means that the product_no is not existing. We find no reason to display dw_product_check DataWindow control to the user, so, turn off its Visible property. Do you remember what we should do before we do any database operation on this DataWindow control? I am sure you guessed it by this time! We need to set the transaction object. Write the following code:

 // Object: Window w_product_master  // Event: Open  // Append the following line to the existing code. dw_product_check.SetTransObject( SQLCA ) Write the following code in the ItemChanged event for the dw_product DataWindow.

 // Object: dw_product in w_product_master Window  // Event: ItemChanged If This.GetColumnName() = "product_no" And & 

11 d i 15

06/08/2012 11 16

powerbuilder: Powerscript

http://belajar-powerbuilder.blogspot.com/search/label/Powerscript

( This.GetItemStatus( Row, 0, Primary! ) = New! Or &  This.GetItemStatus( Row, 0, Primary! ) = &  NewModified! ) Then dw_product_check.Retrieve( Integer( Data ) ) If dw_product_check.RowCount() = 1 Then MessageBox( "Error", "Product No: '" + Data + &  " ->" + &  dw_product_check.GetItemString(Row, &  "product_description") +&  "' already exists.", StopSign!, OK!,1) Return 1 End If  End If  This code works fine here, because, product_description column is defined as NOT NULL in the database, meaning product_description column always contain something and it is never null. If the column allows NULL value, and if the content of the product_description for that product is NULL, then the MessageBox() will never display, because you are sending a NULL value as the parameter to the MessageBox(). If you want to learn about how the MessageBox() function behaves when the message text is NULL value, Place a CommandButton in w_script_practice and write string ls_null; MessageBox( "Test", ls_null), run that window and click on that button. You will never see that message box being popped up.) If that is the case, call GetItemString() on a separate line and check for the NULL value, substitute with appropriate message and then display it. For ex:

String l_desc1 l_desc1 = dw_product_check.GetItemString( Row, &  "product_description" ) if IsNull( l_desc1 ) Then l_desc1 = "Not Defined." MessageBox( "Error", "Product No: '" + l_desc1 + &  "' already exists, StopSign!, OK!,1) The first IF statement is checking for two things. One, whether the user is tabbing out of product_no column or any other column. We are interested in it only if the user is leaving product_no column. GetColumnName() returns the current column name. Just FYI, GetColumn() returns the column number. As you have learned in the "DataWindow Buffers" section, a row can be in one of the four

12 d i 15

06/08/2012 11 16

powerbuilder: Powerscript

http://belajar-powerbuilder.blogspot.com/search/label/Powerscript

statuses. New!, NewModified!, NotModified!, DataModified!. Typically, user might enter the product_no, since it is the first column in the DataWindow. When the row is inserted, it is in the New! status and remains in the New! status till the user presses the tab and the ItemChanged event completes the script execution successfully. That's why we check for the New! status. Sometimes, user might enter data in the new record and navigate to other records and come back to change the product_no. For that reason, we need to check for the NewModified! status. GetItemStatus() gives the status of the specified column, in the specified buffer. If you specify the column number as 0 (zero), it returns the row status, instead of the column status. The third argument is the buffer name. Here, we are interested in the Primary buffer. PowerBuilder sends the data entered by the user as parameters to this event in the Data variable. Remember that it is always in the string format. We need to convert into appropriate formats. The next line is bringing data from the database. Observe the datatype conversion of the Retrieve() function parameter. RowCount() function returns the number of rows in the specified DataWindow. If the row count is greater than zero, it means that the given product is existing in the product_master. (Here, we are checking for 1 because, the product_no in product_master table is unique, meaning product_master would never have multiple records for a given product_no. Checking for >0 instead of = 1 will also serve the purpose; It is useful when you are expecting one or more rows.) Then we are displaying the error information by using the MessageBox() function. The last line Return 1 is very important. This statement tells PowerBuilder, what it has to do after completing the script execution. D I P O S K A N O L E H V I R T U E DI 2 2 : 0 0

TIDAK ADA KOMENTAR:

L I N K K E P O ST I N G I N I

L A B E L : POWERSCRIPT

PrintPage Event in powerbuilder This event occurs for each page printed (just before the page gets printed. Please note that, RetrieveRow event occurs after the row is retrieved by PowerBuilder, but before it displays on the screen). This event gets PageNumber that will be printed as well as the number of the copy, Copy as parameters to this event.

 // Object: DataWindow dw_product in w_product_master window  // Event: PrintPage w_mdi_frame.SetMicroHelp( "Printing Page # " + &  String( PageNumber) ) In fact, you need not code the

13 d i 15

06/08/2012 11 16

powerbuilder: Powerscript

http://belajar-powerbuilder.blogspot.com/search/label/Powerscript

above script, because, when you call DataWindow's Print() function with TRUE as an argument, PowerBuilder automatically displays the page number being printed and also allows you to cancel if needed. If you want to skip printing a particular page, return 1 as the return value from this event D I P O S K A N O L E H V I R T U E DI 2 1 : 5 9

TIDAK ADA KOMENTAR:

L I N K K E P O ST I N G I N I

L A B E L : POWERSCRIPT

PrintStart Event in powerbuilder This event occurs as soon as PowerBuilder starts printing. The total number of pages that are going to print, PagesMax, is passed as parameter to this event. You might want to ask the user whether the printer has that many papers in the tray or not. However, you can’t stop printing from this event programmatically, instead you need to code in the PrintPage event.

 // Object: DataWindow dw_product in w_product_master window  // Event: PrintStart w_mdi_frame.SetMicroHelp( "Starting to Print…" ) D I P O S K A N O L E H V I R T U E DI 2 1 : 5 7

TIDAK ADA KOMENTAR:

L I N K K E P O ST I N G I N I

L A B E L : POWERSCRIPT

KAMIS, 12 JUNI 2008

RetrieveEnd Event in Powerbuilder This event triggers as soon as the last row of the result set is retrieved. The total number of retrieved rows is passed to this event as a event parameter, RowCount.

// Object: DataWindow "dw_query" in w_ product_master window // Event: RetrieveEnd w_mdi_frame.SetMicroHelp( "Rows Retrieved: " + & String( RowCount ) + & ". Query execution complete.") D I P O S K A N O L E H V I R T U E DI 0 9 : 3 7

TIDAK ADA KOMENTAR:

L I N K K E P O ST I N G I N I

L A B E L : POWERSCRIPT

RetrieveRow Event in Powerbuilder This event triggers immediately after retrieving each row and before displaying it on the screen. This is the right place to write the code, if you want to do some process on the row, before the user sees the row on the screen. Writing code in this event an d setting the Asynchronous option of the transaction object to TRUE, makes PowerBuilder to display the row on the screen, as soon as the code in this event is executed. For example, say the result set of a query has 10,000 rows.

14 d i 15

06/08/2012 11 16

powerbuilder: Powerscript

http://belajar-powerbuilder.blogspot.com/search/label/Powerscript

User will see the data on the screen only when PowerBuilder completes retrieving 10,000

th

row*. By writing code in this event (even a

single line comment), user will see the data on the screen as soon as the first row is received by PowerBuilder (of course, code for this event is executed before it is displayed on the screen). By writing code or comment increases the total time required to retrieve the result set. To reduce the time, you might want to write the code in the RetrieveEnd (explained later), which is executed after retrieving all the rows in the result set. Writing code for

the

RetrieveRow

or

RetrieveEnd

depends

on

the

application

requirement. * There is an exception to this behavior. If RetrieveAsNeeded option i s set, PowerBuilder displays data as soon it completes retrieving one screen full of data. Whenever user tries to scroll down the screen, another screen full of data will be retrieved. PowerBuilder, depending on the DataWindow control size at run-time determines the number of  rows that fit on a single screen. Another exception is, you should not use aggregate functions—such as Sum(), Avg(), Min(), Max(), Count()—etc in the DataWindow and should not set the sort criteria in the DataWindow. In this situation, PowerBuilder needs the full result set in order to calculate the aggregate functions or to sort the data. The following code displays the number rows retrieved on the status bar like a counter.

// Object: DataWindow dw_query in w_product_master window // Event: RetrieveRow w_mdi_frame.SetMicroHelp( "Rows Retrieved: " + & String( row ) ) D I P O S K A N O L E H V I R T U E DI 0 9 : 3 6

TIDAK ADA KOMENTAR:

L I N K K E P O ST I N G I N I

L A B E L : POWERSCRIPT

Beranda

Posting Lama

Langganan: Entri (Atom)

15 d i 15

06/08/2012 11 16

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF