Textbox Problem

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

franco
Posts: 820
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: Textbox Problem

Post by franco »

As I said at the start this small program does not have a problem. My pos program is quite large.
This only started happening after I installed 3.4.4 in a slower windows 10 computer, intel duel core 3050 2.16 ghz. 4 gigs ram.
But the compiled program has problem in all computers.
I am going to try to install 3.2 in the windows 10 computer and see if it happens.The compiled program is 33% larger in 3.4.4 so it must be doing a lot more inside. Then we will se if it is 3.44, it could be. Maybe I have not set it up properly. I just installed it nothing special.
Thanks for your responces and I will let you know.
Franco
All The Best,
Franco
Canada
franco
Posts: 820
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: Textbox Problem

Post by franco »

Back to this problem. My error program designed for me by Edward (Thanks Edward) does not catch error for _Inputbox not active. Can anyone
Help me add an code to my error program to catch this error and return to the program without exiting program with Windows error.
Like in error function

Code: Select all

If oError:genCode == EG   ???????
HMG_keyboardclearbuffer()                     \\or  HMG_GetLastCharacterEX()
return .T.
Thanks in advance .............. Franco
All The Best,
Franco
Canada
User avatar
serge_girard
Posts: 3166
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Textbox Problem

Post by serge_girard »

Franco,

Did you #include "error.ch" ?

Serge
There's nothing you can do that can't be done...
edk
Posts: 911
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Textbox Problem

Post by edk »

Franco, You can try to delay an event call, like

Code: Select all

ONENTER millisec(50)
Or, if this error occurs, look in the ErrorLog.htm file and find where this error is generated.
Should be given a procedure / function name and possibly a line number (in brackets).
Then you can look for a solution in HMG sources.

You can also try to change textbox name, _InputBox is used internally in HMG sources, in file h_windows.prg at line 5334, maybe this is cause?
KDJ
Posts: 243
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland

Re: Textbox Problem

Post by KDJ »

This is a problem of events synchronization.
The program tries to release the window before its activation.
My solution - small fix in InputBox function (see InputBox2):

Code: Select all

#include <hmg.ch>


//added
MEMVAR _HMG_SYSDATA
MEMVAR MYBOXV, V_QTY, RE
//


Function Main
PUBLIC MYBOXV:= '', V_QTY := 0, RE := 'F'

        DEFINE WINDOW FORM_1 ;
		AT 0,0 ;
		HEIGHT 360 WIDTH 510 ;
		TITLE ' Enter Speed Test' ;
		MAIN
		
		DEFINE BUTTON BUTTON_1
		ROW 60
		COL 145
		WIDTH 120
		HEIGHT 80
		CAPTION 'Enter Item'
		ACTION { || {ADDTOINVOICE()}}
		END BUTTON
		
		END WINDOW
        FORM_1.Center
        FORM_1.Activate

Return NIL

FUNCTION ADDTOINVOICE
	LOCAL M_ITEM
	MYBOX('Add to Invoice')
	M_ITEM := UPPER(MYBOXV)
	MYBOXV:= ""
	IF RE = 'T'
		RE := 'F'
		RETURN NIL
	ENDIF
	**** This is where crash is if hit enter key twicw very fast in function mybox
	**** This little program does not crash it is not doing much
	V_QTY := VAL(INPUTBOX2('Enter Quantity','Quantity', '1'))
	MSGBOX(M_ITEM+'     '+STR(V_QTY))
	
RETURN NIL

FUNCTION MYBOX(Tit)

	            // Private variable myboxv must be set to use as return variable to change
	DEFINE WINDOW Mybox ;
		AT  getDeskTopHeight()/2-50 ,getdesktopWidth() /2-175 ;
		WIDTH 350 ;
		HEIGHT 150 ;
		TITLE TIT ;
		MODAL 
		
		DEFINE LABEL LAB1
         ROW 10
         COL 10
         WIDTH 280
         HEIGHT 20
		 VALUE 'Enter Text    (Escape/Blank to Exit)'
	END LABEL
	
	DEFINE TEXTBOX TEXT1
         ROW 30
         COL 10
         WIDTH 280
         HEIGHT 30

     //fixed
		 //ON ENTER { ||  {MYBOXV := MYBOX.TEXT1.VALUE}, {MyBox.Release} }
		 ON ENTER If(IsWindowActive(Mybox), (MYBOXV := MYBOX.TEXT1.VALUE, MyBox.Release), NIL)
     //

											// MessageBoxTimeout(,,,500)  //works
	END TEXTBOX
	
		*SetKeys('MYBOX') 
		*ON KEY F1 ACTION Helping('CRSWin.hlp')
		ON KEY ESCAPE OF MyBox Action { || { re := 'T' } ,{MyBox.Release} }	 
		END WINDOW
		
		*MYBOX.TEXT1.VALUE := MYBOXV
		*MYBOX.TEXT1.SETFOCUS
		Mybox.Activate

	Return  NIL



// Pablo César (January 2015)
// KDJ (2017-06-11)
*-----------------------------------------------------------------------------*
Function InputBox2 ( cInputPrompt , cWindowTitle , cDefaultValue , nTimeout , cTimeoutValue , lMultiLine , nWidth )
*-----------------------------------------------------------------------------*
Local RetVal , mo

DEFAULT cInputPrompt   := ""
DEFAULT cWindowTitle   := ""
DEFAULT cDefaultValue  := ""

If !(nWidth=Nil)
   If nWidth<350
      nWidth:=350
   Endif
Endif

RetVal := ''

If ValType (lMultiLine) != 'U'
    If lMultiLine == .T.
        mo := 150
    Else
        mo := 0
    EndIf
Else
    mo := 0
EndIf

DEFINE WINDOW _InputBox                ;
    AT 0,0                             ;
    WIDTH If(nWidth=Nil, 350, nWidth)  ;
    HEIGHT 115 + mo + GetTitleHeight() ;
    TITLE cWindowTitle                 ;
    MODAL                              ;
    NOSIZE                             ;
    FONT 'Arial'                       ;
    SIZE 10

    ON KEY CONTROL+W ACTION ( _HMG_SYSDATA [ 257 ] := .F. , RetVal := _InputBox._TextBox.Value , _InputBox.Release ) 
    ON KEY ESCAPE ACTION ( _HMG_SYSDATA [ 257 ] := .T. , _InputBox.Release )

    @ 07,10 LABEL _Label    ;
        VALUE cInputPrompt  ;
        WIDTH 280 

    If ValType (lMultiLine) != 'U' .and. lMultiLine == .T.
       @ 30,10 EDITBOX _TextBox ;
            VALUE cDefaultValue ;
            HEIGHT 26 + mo      ;
            WIDTH If(nWidth=Nil, 320, nWidth-30) 
    else
        @ 30,10 TEXTBOX _TextBox                 ;
            VALUE cDefaultValue                  ;
            HEIGHT 26 + mo                       ;
            WIDTH If(nWidth=Nil, 320, nWidth-30) ;
            ON ENTER If(IsWindowActive(_InputBox), ( _HMG_SYSDATA [ 257 ] := .F. , RetVal := _InputBox._TextBox.Value , _InputBox.Release ), NIL)
            //ON ENTER ( _HMG_SYSDATA [ 257 ] := .F. , RetVal := _InputBox._TextBox.Value , _InputBox.Release )
            //KDJ (2017-06-11)

    endif

    @ 67+mo,If(nWidth=Nil, 120, (nWidth/2)-10-100) BUTTON _Ok        ;
        CAPTION _hMG_SYSDATA [ 128 ] [8]                             ;
        ACTION ( _HMG_SYSDATA [ 257 ] := .F. , RetVal := _InputBox._TextBox.Value , _InputBox.Release ) 
    
    @ 67+mo,If(nWidth=Nil, 230, (nWidth/2)+10) BUTTON _Cancel        ;
        CAPTION _hMG_SYSDATA [ 128 ] [7]                             ;
        ACTION   ( _HMG_SYSDATA [ 257 ] := .T. , _InputBox.Release )
    
    If ValType (nTimeout) != 'U'
        If ValType (cTimeoutValue) != 'U'
            DEFINE TIMER _InputBox ;
            INTERVAL nTimeout ;
            ACTION  ( RetVal := cTimeoutValue , _InputBox.Release ) 
        Else
            DEFINE TIMER _InputBox ;
            INTERVAL nTimeout ;
            ACTION _InputBox.Release
        EndIf
    EndIf
END WINDOW
_InputBox._TextBox.SetFocus 
CENTER WINDOW _InputBox
ACTIVATE WINDOW _InputBox   
Return ( RetVal )
franco
Posts: 820
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: Textbox Problem

Post by franco »

Serge thanks for responce. Should I put my error function at the bottom of my main module or in my procedure file.
Thanks Edward I tried this but still crashes.
KDJ great work I will give a try.
I find the same problem in textboxes and buttons.
I am going to move everything back to 3.2 and see if still happens. Will take a bit of time as I have to remove some of my changes.
Thank you all ..... Franco
All The Best,
Franco
Canada
User avatar
serge_girard
Posts: 3166
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Textbox Problem

Post by serge_girard »

Hi Franco,

I put it ant the end of my main proc.
If you wrote the errorsys.prg your self (or changed it heavily) put this at the top of deferror:

Code: Select all

LOCAL n := 1

DO WHILE !(PROCNAME(n) == "")
   IF UPPER(ALLTRIM(PROCNAME(n))) == 'DEFERROR'
       QUIT
   ENDIF
   n++
ENDDO
This will end recursive calls to deferror itself when you have an error in deferror...

Serge
There's nothing you can do that can't be done...
franco
Posts: 820
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: Textbox Problem

Post by franco »

Thanks Serge, I will give it a try.
Franco
All The Best,
Franco
Canada
franco
Posts: 820
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: Textbox Problem

Post by franco »

KDJ,
I added what you suggested but still would not stop the problem, but I added at the bottom before return this fix and works fine.
It stops any additional characters in keyboard buffer.

Code: Select all

DEFINE TEXTBOX TEXT1
         ROW 30
         COL 10
         WIDTH 280
         HEIGHT 30

     //fixed
		 //ON ENTER { ||  {MYBOXV := MYBOX.TEXT1.VALUE}, {MyBox.Release} }
		 ON ENTER If(IsWindowActive(Mybox), (MYBOXV := MYBOX.TEXT1.VALUE, MyBox.Release), NIL)
     //

											// MessageBoxTimeout(,,,500)  //works
	END TEXTBOX
	
		*SetKeys('MYBOX') 
		*ON KEY F1 ACTION Helping('CRSWin.hlp')
		ON KEY ESCAPE OF MyBox Action { || { re := 'T' } ,{MyBox.Release} }	 
		END WINDOW
		
		*MYBOX.TEXT1.VALUE := MYBOXV
		*MYBOX.TEXT1.SETFOCUS
		Mybox.Activate
                // Franco addition and now works
                HMG_KeyboardClearBuffer()
       	Return  NIL
Thanks again, Franco
All The Best,
Franco
Canada
Post Reply