oWnd:bKeydown does not trigger when DEL key pressed

Post Reply
Gale FORd
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston
Contact:

oWnd:bKeydown does not trigger when DEL key pressed

Post 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?
Gale FORd
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston
Contact:

Post by Gale FORd »

I was hoping that I did not need to do that on every get, but if I must I must.
Gale FORd
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston
Contact:

Post 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.
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

In both cases you can do something similar to this:

Code: Select all

FOR i = 1 TO LEN( oDlg:aControls )
    IF oDlg:aControls[ i ]:ClassName() = "TGET"
        oDlg:aControls[ i ]:bLostFocus = ...
    ENDIF
NEXT
EMG
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post 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
Gale FORd
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston
Contact:

Post 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.
Gale FORd
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston
Contact:

Post 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.
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post 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

  ...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
Gale FORd
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston
Contact:

Post 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.
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post 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
Post Reply