Page 1 of 1

oWnd:bKeydown does not trigger when DEL key pressed

PostPosted: Fri May 26, 2006 9:37 pm
by Gale FORd
I want to have a save button activate when changes are made to fields on window.

The line below works for most keys, but the Delete and Back keys are ignored.

::oWnd:bKeyDown = { | nKey | if( ! self:lSave .and. (( nKey > 31 .and. nKey < 223) .or. nKey = VK_BACK .or. nKey = VK_DELETE), self:togglesave(), ) }

Is there another (easier) way to detirmine if control changes?

Re: oWnd:bKeydown does not trigger when DEL key pressed

PostPosted: Sat May 27, 2006 9:00 am
by Enrico Maria Giordano
Try assigning

oGet:bChange

codeblock.

EMG

PostPosted: Tue May 30, 2006 2:09 pm
by Gale FORd
I was hoping that I did not need to do that on every get, but if I must I must.

PostPosted: Tue May 30, 2006 2:23 pm
by Enrico Maria Giordano
Then try assigning

oGet:bLostFocus

codeblock.

EMG

PostPosted: Tue May 30, 2006 2:40 pm
by Gale FORd
I'm sorry, but that seems like a similar issue. Every get will need to be touched with some routing to check for changes.

PostPosted: Tue May 30, 2006 3:04 pm
by Enrico Maria Giordano
In both cases you can do something similar to this:

Code: Select all  Expand view
FOR i = 1 TO LEN( oDlg:aControls )
    IF oDlg:aControls[ i ]:ClassName() = "TGET"
        oDlg:aControls[ i ]:bLostFocus = ...
    ENDIF
NEXT


EMG

PostPosted: Tue May 30, 2006 4:17 pm
by James Bott
Gale,

If you are using TDatabase (or TData) there is a method Modified() that checks the buffer data (in aBuffer) against the data on the disk to see if there have been any changes.

If you are not using TDatabase, then you can store a copy of all the data in the dialog in an array before the edit, then check it against the array after. This, of course, requires more hand coding which may not be feasible if you have a lot of controls and/or a lot of dialogs.

This is one very good reason (of many) to be using database objects.

James

PostPosted: Tue May 30, 2006 4:23 pm
by Gale FORd
using bChange does not work either. When backspace or delete key pressed the bChange is not getting fired.

Here is routine I use
FOR nCounter := 1 TO LEN( oDlg:aControls )
IF oDlg:aControls[ nCounter ]:ClassName() = "TGET" .or. oDlg:aControls[ nCounter ]:ClassName() = "TCHECKBOX"
if oDlg:aControls[ nCounter ]:bChange == nil
// tracelog( oDlg:aControls[ nCounter ]:ClassName() )
oDlg:aControls[ nCounter ]:bChange = { || ::togglesaveon() }
endif
ENDIF
NEXT

I verified with tracelog that proper controls were getting bChange assigned.

PostPosted: Tue May 30, 2006 4:30 pm
by Gale FORd
James,

I am trying to add a save button that shows when a change is made.
I use tdatabase but that only works when you check it.

If you change a get then tab to next get there is no visable indication data has changed. I was just wanting a button that would activate showing the user that changes have been made and a save is necessary.

PostPosted: Tue May 30, 2006 4:33 pm
by James Bott
Gale,

I just had an idea how you can test for changes without much code even if you are not using TDatabase.

At the start of the dialog using the ON INIT clause call something like this:

Code: Select all  Expand view
  ...on init originalData( oDlg )

function originalData( oDlg )
   local i:=0, aBuffer:={}
   for i = 1 to len( oDlg:aControls )
       aadd( aBuffer, oDlg:aControls[i] )
   next
return aBuffer


Then at the end, use something similar to check for changes.

James

PostPosted: Tue May 30, 2006 4:45 pm
by Gale FORd
Sorry, I forgot to add my folders on a for next loop

FOR nCounter := 1 TO LEN( oFld:aDialogs[ 1 ]:aControls )
IF oFld:aDialogs[ 1 ]:aControls[ nCounter ]:ClassName() = "TGET" .or. oFld:aDialogs[ 1 ]:aControls[ nCounter ]:ClassName() = "TCHECKBOX"
if oFld:aDialogs[ 1 ]:aControls[ nCounter ]:bChange == nil
tracelog( oFld:aDialogs[ 1 ]:aControls[ nCounter ]:ClassName() )
oFld:aDialogs[ 1 ]:aControls[ nCounter ]:bChange = { || ::togglesaveon() }
endif
ENDIF
NEXT

It is working generally. I may have to change it to your suggestion using bLostFocus and adding a check for oDbf:modified().

Sometimes the backspace or delete keys trigger bChange even though nothing is changed.

PostPosted: Tue May 30, 2006 4:46 pm
by James Bott
Gale,

Apparently you posted your last message while I was writing my previous reply.

You can just check the oDBF:modified() method in the valid clause of each control.

...VALID if( oDBF:modified(), oSave:enable(),)

James