FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour oWnd:bKeydown does not trigger when DEL key pressed
Posts: 663
Joined: Mon Dec 05, 2005 11:22 PM
oWnd:bKeydown does not trigger when DEL key pressed
Posted: Fri May 26, 2006 09:37 PM

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?

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: oWnd:bKeydown does not trigger when DEL key pressed
Posted: Sat May 27, 2006 09:00 AM

Try assigning

oGet:bChange

codeblock.

EMG

Posts: 663
Joined: Mon Dec 05, 2005 11:22 PM
oWnd:bKeydown does not trigger when DEL key pressed
Posted: Tue May 30, 2006 02:09 PM

I was hoping that I did not need to do that on every get, but if I must I must.

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
oWnd:bKeydown does not trigger when DEL key pressed
Posted: Tue May 30, 2006 02:23 PM

Then try assigning

oGet:bLostFocus

codeblock.

EMG

Posts: 663
Joined: Mon Dec 05, 2005 11:22 PM
oWnd:bKeydown does not trigger when DEL key pressed
Posted: Tue May 30, 2006 02:40 PM

I'm sorry, but that seems like a similar issue. Every get will need to be touched with some routing to check for changes.

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
oWnd:bKeydown does not trigger when DEL key pressed
Posted: Tue May 30, 2006 03:04 PM
In both cases you can do something similar to this:

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


EMG
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
oWnd:bKeydown does not trigger when DEL key pressed
Posted: Tue May 30, 2006 04:17 PM

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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 663
Joined: Mon Dec 05, 2005 11:22 PM
oWnd:bKeydown does not trigger when DEL key pressed
Posted: Tue May 30, 2006 04:23 PM

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.

Posts: 663
Joined: Mon Dec 05, 2005 11:22 PM
oWnd:bKeydown does not trigger when DEL key pressed
Posted: Tue May 30, 2006 04:30 PM

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.

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
oWnd:bKeydown does not trigger when DEL key pressed
Posted: Tue May 30, 2006 04:33 PM
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:

  ...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
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 663
Joined: Mon Dec 05, 2005 11:22 PM
oWnd:bKeydown does not trigger when DEL key pressed
Posted: Tue May 30, 2006 04:45 PM

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.

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
oWnd:bKeydown does not trigger when DEL key pressed
Posted: Tue May 30, 2006 04:46 PM

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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10

Continue the discussion