Tuesday 15 November 2016

7. Datawindow Operations using Code

Multiple table update on Datawindow


Updates on Data window can be applied using two overloads:

  1. dwcontrol.Update()
  2. dwcontrol.Update ( { boolean accept {, boolean resetflag } } )

the 2nd overload has two parameters:
- Accept will perform acceptext() before updation. if validation fails on acceptext(),
Update fails.this is by default true on 1st overload of upload.
- resetflag will set the flag that the fields are updated & reflected to Db. By default,
  it is set to true on 1st overload.

Code Implementation

// this will update the table1 set to update on datawindow & set resetflag to false.
  dw_datawindow.update(true,false);





 // disable table update to previous columns of table 1
  dw_datawindow.Modify("column1.Update = No")
  dw_datawindow.Modify("column2.Update = No")
  dw_datawindow.Modify("column3.Key = No")

  // update table changed to this new table 2 & columns
   dw_datawindow.Modify("DataWindow.Table.update = ~"db_name..table_2~"")
   dw_datawindow.Modify("column_1fortable2.Update = Yes")
   dw_datawindow.Modify( "column_2fortable2.Update = Yes")
   dw_datawindow.Modify("column_3fortable2.Update = Yes")
   dw_datawindow.Modify("column_4fortable2.Update = Yes")
   dw_datawindow.Modify("column_5fortable2.Update = Yes")
   dw_datawindow.Modify("column_6fortable2.Key = Yes")


dw_datawindow.Update();  



  // setting back the table1 as updatable table
  dw_datawindow.Modify("DataWindow.Table.update = ~"db_name..table_1~"")
  dw_datawindow.Modify("column1.Update = Yes")
  dw_datawindow.Modify("column2.Update = Yes")
  dw_datawindow.Modify("column3.Key = Yes")

  // disable table update to previous columns
   dw_datawindow.Modify("column_1fortable2.Update = no")
   dw_datawindow.Modify( "column_2fortable2.Update = no")
   dw_datawindow.Modify("column_3fortable2.Update = no")
   dw_datawindow.Modify("column_4fortable2.Update = no")
   dw_datawindow.Modify("column_5fortable2.Update = no")
   dw_datawindow.Modify("column_6fortable2.Key = no")








Sunday 13 November 2016

6. Coding

Calling functions in powerbuilder:


Syntax
{ objectname.} { type } { calltype } { when } name ( { argumentlist } )


objectname :   this(default) ; objectname
type :    function(default); event
calltype : Static(default) ; dynamic

     dynamic keyword is used when there is no need to resolve the function name at compilation. On Running, it resolves the function name & gives error if function doesn't exist.
      this is used when child object have parent reference and we want to call a child function not in parent. 

when : trigger(default) ; post

    When you post a function or event, it is added to the object’s queue and executed in its turn. In most cases, it is executed when the current script is finished; however, if other system events have occurred in the meantime, its position in the queue might be after other scripts. Its return value is not available to the calling script.


isnull vs valid 

isnull() in powerbuilder is to check for nullity of expression or variable.
IsValid() is used to check whether reference is null or initialized.

isvalid(obect type) & isnull(expression/variable).



Debugging Application


For debugging, insert breakpoints on code using right click or use keyboard shortcut to assign.

1.







2.




3.
The buttons highlighted in this is used for debugging.  The yellow pointer on code shows the current execution line on which debugger is.