A few quick suggestions, though a lot more is need to be done. This is to atleast ensure that invalid and unintended values are not written to the data.
1. bPostEdit block receives three paramters. ( oCol, uValueEntered, oGet'snLastkey). Programmer should write bPostEditBlock to write changes to the database after checking the nLastKey. Safe to write data when the 3rd parameter nLastKey == VK_ENTER. In the above example the postedit block would be :
- Code: Select all Expand view
oBrw:aCols[1]:bOnPostEdit := {|o,x,n| if ( n == 13, aLin[ oBrw:nArrayAt,1] := x, ) }
2. While this is what the programmer has to do, this does not solve the problem, because due the way CancelEdit method is written, bPostEdit is always called with VK_RETURN as the last key even though the Get is exited by Escape or
losing focus. A fix in CancelEdit method is required;
- Code: Select all Expand view
if oCol:oEditGet != nil
// The nexline should be commented out
// oCol:oEditGet:nLastKey := VK_RETURN
oCol:PostEdit()
endif
3. Now the PostEdit block is expected to be called with the real oGet's last key. If the user exited with Escape or by
losing focus of get, VK_ENTER is not expected to be the last key as seen by the PostEdit block.
Still there is a problem in some cases. User enters invalid value and presses Enterkey. Valid Block does not allow the input. User wants to give up and clicks on another cell so that get loses its focus. Then also PostEdit block is called and in this case the last key is VK_ENTER. When Get is created get's bLostFocus is set to {||::PostEdit()}. So when the get loses focus it calls PostEdit method without parameters. This call to postedit does not go through CancelEdit method.
A suggested fix is :
- Code: Select all Expand view
while initializing the Get:
::oEditGet:bLostFous := {|| PostEdit(nil,nil, VK_ESCAPE)} // can be any value to indicate loss of focus.
PostEdit method:
method postedit( xValue, lButton, nLastKey )
...
..
..
case ::nEditType == EDIT_GET
If ::oEditGet != nil
// insert the following 3 lines
if nLastKey != nil
::oEditGet:nLastKey := nLastKey
endif
With these changes I could prevent writing of invalid data. By abundant caution I am once again checking bValidBlock within PostEdit block, which will not be necessary once the edit behaviour is fully rectified.
Still I have a problem and not able to find a solution. Enter an invalid value and press enter. Later with escape key or
losing focus, exit edit ( atleast user thinks he exited the edit ). But I find that the GetObject is still there. When we navigate back to that cell, Get is shown again. Yet to find what to do for this.
This discussion is limited to single line edit in case of nEditType = 1 only. I have not mentioned the problems with edittypes 2 and above.
Hope we can get xBrowse with inline edit that can be used in real applications with 7.12