Strange behaviour of LastKey()

Strange behaviour of LastKey()

Postby driessen » Sun Feb 18, 2007 2:08 pm

Hello,

I noticed that LastKey() has a strange behaviour.

This is my code :

-------------------------------------

PRIVATE Niv := 1

DEFINE DIALOG DiaDlg NAME "DIALOG"

REDEFINE oGET1 VAR FIELD1 ID 101 OF DiaDlg PICTURE "XXX"
...
REDEFINE oGET9 VAR FIELD9 ID 109 OF DiaDlg PICTURE "XXX"

REDEFINE BUTTON ID 200 OF DiaDlg ACTION(Niv:=9,DiaDlg:End())
REDEFINE BUTTON ID 201 OF DiaDlg ACTION(Niv:=0,DiaDlg:End())

ACTIVATE DIALOG DiaDlg CENTERED

IF LastKey() = VK_ESCAPE ; Niv := 0 ; ENDIF

-------------------------------------

What do I want to do ?

Button 200 is a button "Save"
Button 201 is a button "Quit"

If niv = 9, the data will be saved. If niv = 0, the program will check whether there is a difference between the data on the screen and the data on disk. If all the data are the same, the procedure will be ended, otherwise the user will be asked if he is sure that the data will not be saved.

I want that the user also can use the Escape-key which has to behave like the button "Quit".

So, If the user clicks "Quit", niv = 0 but also if the Escape-key is pressed, niv = 0.

But what is happening ?

Once I have pressed the Escape-key, lastkey() keeps positioned on the Escape-key. If button "Save" is clicked the next time, the program will always act as if the Escape-key has been pressed.

I added the test : MsgInfo(LastKey()). It always returns (27 = Escape), even it the lastkey wasn't the Escape-key at all.

Can anyone tell me what's wrong ?

Thank you very much in advance for any help.

Michel
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Strange behaviour of LastKey()

Postby Richard Chidiak » Sun Feb 18, 2007 3:22 pm

Michel

Try it this way

ACTIVATE DIALOG ODLG CENTERED VALID ( ESC_DIALOG() )

FUNCTION ESC_DIALOG
IF GETASYNCKEY( 27 )
IF msgyesno("Voulez-vous tout annuler ?","Veuillez confirmer")
return .T.
ELSE
return .F.
ENDIF
ENDIF
return .T.


Hth

Richard
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Postby driessen » Sun Feb 18, 2007 3:50 pm

Richard,

Thank you very much for your help.

I think you solved my problem.

Michel
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 37 guests