uf_set_row_status() to replace SetItemStatus()


Link to this posting

Postby Ursego » 19 Feb 2013, 21:38

Don't use SetItemStatus() function directly - it doesn't change any old status to any new status.

You can find the problem combinations in this table:

Image

As you see, there are some item statuses that cannot be set directly; you need a second SetItemStatus() to achieve the goal. One example: changing the row status from New! to NotModified! simply doesn't work. You need to set it to DataModified! first, then you can change it to NotModified!. Some others settings are allowed, but don't work as expected; changing from NewModified! to NotModified! will change the status to New!. To encapsulate all that complexity (and forget about it forever), create a function (named, for example, uf_set_row_status - to show it sets ROW's status, not COLUMN's) in a class of useful functions or another class in your application (maybe in the DW ancestor - in this case remove the argument adw and use this instead):

Code: Select all
/**********************************************************************************************************************
Dscr:         Changes the item status of the passed row in a DataWindow.
            Call this function instead of SetItemStatus() which doesn't change any old status to any new status.
            Works on any buffer; to work with Primary! buffer only, use the overloaded version.
***********************************************************************************************************************
Arg:         DataWindow      adw
            long            al_row
            DWItemStatus   a_new_status
            DWBuffer         a_buf
***********************************************************************************************************************
Developer:   Michael Zuskin -  http://linkedin.com/in/zuskin | http://code.intfast.ca/
**********************************************************************************************************************/
boolean         lb_work_done = false // sometimes we have to call SetItemStatus twice to achieve the goal; this var manages the number of calls
DWItemStatus   l_old_status
DWItemStatus   l_changed_status

l_old_status = adw.GetItemStatus(al_row, 0, a_buf)

choose case true
case a_new_status = l_old_status
   return // nothing to do - the row is already in the desired status
case l_old_status = NewModified! and a_new_status = New!
   adw.SetItemStatus(al_row, 0, a_buf, NotModified!) // that changes the row status to New!
   lb_work_done = true // no need in another SetItemStatus
case l_old_status = New! and a_new_status = NotModified!
   adw.SetItemStatus(al_row, 0, a_buf, DataModified!)
case l_old_status = NewModified! and a_new_status = NotModified!
   adw.SetItemStatus(al_row, 0, a_buf, DataModified!)
case l_old_status = DataModified! and a_new_status = New!
   adw.SetItemStatus(al_row, 0, a_buf, NotModified!)
end choose

if not lb_work_done then
   adw.SetItemStatus(al_row, 0, a_buf, a_new_status)
end if

return

Create a similar function for DataStore too. These functions can be also overloaded with a 3-arguments version which will be called when only the Primary buffer is processed:

Code: Select all
/**********************************************************************************************************************
Dscr:         Changes the item tatus of the passed row in a DataWindow.
            Call this function instead of SetItemStatus() which doesn't change any old status to any new status.
            Works only on Primary! buffer; to work with other buffers, use the overloaded version.
***********************************************************************************************************************
Developer:   Michael Zuskin -  http://linkedin.com/in/zuskin | http://code.intfast.ca/
***********************************************************************************************************************
Arg:   DataWindow      adw
      long            al_row
      DWItemStatus   a_new_status
**********************************************************************************************************************/
this.uf_set_row_status(adw, al_row, a_new_status, Primary!)
User avatar
Ursego
Site Admin
 
Posts: 143
Joined: 19 Feb 2013, 20:33



Ketones are a more high-octane fuel for your brain than glucose. Become a biohacker and upgrade yourself to version 2.0!



cron
Traffic Counter

eXTReMe Tracker