oWnd:bKeydown does not trigger when DEL key pressed

oWnd:bKeydown does not trigger when DEL key pressed

Postby Gale FORd » Fri May 26, 2006 9: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?
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston


Postby Gale FORd » Tue May 30, 2006 2:09 pm

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

Postby Enrico Maria Giordano » Tue May 30, 2006 2:23 pm

Then try assigning

oGet:bLostFocus

codeblock.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8389
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Gale FORd » Tue May 30, 2006 2: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.
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Postby Enrico Maria Giordano » Tue May 30, 2006 3:04 pm

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

Postby James Bott » Tue May 30, 2006 4: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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Gale FORd » Tue May 30, 2006 4: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.
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Postby Gale FORd » Tue May 30, 2006 4: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.
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Postby James Bott » Tue May 30, 2006 4: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:

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

Postby Gale FORd » Tue May 30, 2006 4: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.
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Postby James Bott » Tue May 30, 2006 4: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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 33 guests

cron