Page 1 of 1

Uppercase in textbox (HMG4)

Posted: Fri Jul 29, 2011 2:08 am
by pctoledo
Hi Friends, how to convert characters to uppercase in textbox?

Re: Uppercase in textbox (HMG4)

Posted: Sun Jul 31, 2011 11:19 am
by pctoledo
Friends, to decide the problem with CaseConvert and MaxLength, I modified the file textbox.prg:

// Internal Data

Code: Select all

   DATA nMaxLength                                INIT   0

Code: Select all

METHOD MaxLength( nValue ) CLASS TEXTBOX

   IF PCOUNT() == 0
      RETURN ::nValue
   ELSEIF PCOUNT() == 1
      ::nMaxLength := nValue
   ENDIF

   RETURN NIL

Code: Select all

METHOD CASEConvert( nValue ) CLASS TEXTBOX

   IF PCOUNT() == 0
      RETURN ::nValue
   ELSEIF PCOUNT() == 1
      ::nCaseConvert := nValue
   ENDIF

   RETURN NIL

Code: Select all

METHOD ProcessTextChange( cText ) CLASS TEXTBOX
   LOCAL icp, InBufferLeft, InBufferRight

   HB_SYMBOL_UNUSED( cText )

   IF ::lDateTextBoxActive
      ::lDateTextBoxActive := .F.
   ELSE
      icp := ::oQTObject:cursorPosition()
      IF ::nCaseConvert>0
       cText := IF(::nCaseConvert==1,UPPER(cText),LOWER(cText))
       ::oQTObject:setText( cText )
       ::oQTObject:setCursorPosition( icp )
      ENDIF
      IF ::nMaxLength>0
         IF Len( cText ) > ::nMaxLength
            InBufferLeft := Left( cText , icp )
            InBufferRight := Right( cText , Len( cText ) - icp - 1 )
            ::oQTObject:setText( LEFT(InBufferLeft + InBufferRight,::nMaxLength) )
            ::oQTObject:setCursorPosition( icp )
         ENDIF
      ENDIF
      IF Len( ::cInputMask ) > 0
         IF ::cTextBoxType == 'MASKEDTEXT'
            IF ::lMaskedFlag == .T.
               Self:ProcessCharmask( .t. )
             ENDIF
            IF ValType( ::bOnChange ) != 'U'
               Eval( ::bOnChange )
            ENDIF
         ELSEIF ::cTextBoxType == 'CHARMASKTEXT'
            Self:ProcessCharMask()
            IF ValType( ::bOnChange ) != 'U'
               Eval( ::bOnChange )
            ENDIF
         ENDIF

      ELSE

         IF ::cTextBoxType == 'NUMTEXT'
            Self:ProcessNumText()
         ENDIF
         IF ValType( ::bOnChange ) != 'U'
            Eval( ::bOnChange )
         ENDIF
      ENDIF

   ENDIF

RETURN NIL
I do not know if it is the best solution, but it gave certain!

Samples:

Code: Select all

      With Object oFriend := TextBox():New( "oFriend" )
         :Row            := 85
         :Col            := 15
         :Width          := 485
         :Height         := 20
         :ToolTip        := 'Name of the Friend'
         :MaxLength      := 50
         :OnEnter        := { || InsertTab() }
         :CaseConvert    := 1
      End With

Re: Uppercase in textbox (HMG4)

Posted: Sun Jul 31, 2011 12:42 pm
by pctoledo
It gives error with accented letters (ÁÉÃÕÇ) :oops: :cry:

Re: Uppercase in textbox (HMG4)

Posted: Mon Aug 01, 2011 12:14 pm
by pctoledo
Hi Friends, problem resolved:

Code: Select all

METHOD ProcessTextChange( cText ) CLASS TEXTBOX
   LOCAL icp, InBufferLeft, InBufferRight, InBuffer

   HB_SYMBOL_UNUSED( cText )

   IF ::lDateTextBoxActive
      ::lDateTextBoxActive := .F.
   ELSE
      icp := ::oQTObject:cursorPosition()
      IF ::nCaseConvert>0
       InBuffer := ::oQTObject:text()
       InBuffer := IF(::nCaseConvert==1,UPPER(InBuffer),LOWER(InBuffer))
       ::oQTObject:setText( InBuffer )
       ::oQTObject:setCursorPosition( icp )
      ENDIF
      IF ::nMaxLength>0
         InBuffer := ::oQTObject:text()
         IF Len( InBuffer ) > ::nMaxLength
            InBufferLeft := Left( InBuffer , icp )
            InBufferRight := Right( InBuffer , Len( InBuffer ) - icp - 1 )
            ::oQTObject:setText( LEFT(InBufferLeft + InBufferRight,::nMaxLength) )
            ::oQTObject:setCursorPosition( icp )
         ENDIF
      ENDIF
      IF Len( ::cInputMask ) > 0
         IF ::cTextBoxType == 'MASKEDTEXT'
            IF ::lMaskedFlag == .T.
               Self:ProcessCharmask( .t. )
             ENDIF
            IF ValType( ::bOnChange ) != 'U'
               Eval( ::bOnChange )
            ENDIF
         ELSEIF ::cTextBoxType == 'CHARMASKTEXT'
            Self:ProcessCharMask()
            IF ValType( ::bOnChange ) != 'U'
               Eval( ::bOnChange )
            ENDIF
         ENDIF

      ELSE

         IF ::cTextBoxType == 'NUMTEXT'
            Self:ProcessNumText()
         ENDIF
         IF ValType( ::bOnChange ) != 'U'
            Eval( ::bOnChange )
         ENDIF
      ENDIF

   ENDIF

RETURN NIL

Re: Uppercase in textbox (HMG4)

Posted: Mon Aug 01, 2011 1:16 pm
by Rathinagiri
Nice work

Re: Uppercase in textbox (HMG4)

Posted: Tue Aug 02, 2011 8:00 am
by mrduck

Code: Select all

METHOD MaxLength( nValue ) CLASS TEXTBOX

   IF PCOUNT() == 0
      RETURN ::nValue
   ELSEIF PCOUNT() == 1
      ::nMaxLength := nValue
   ENDIF

   RETURN NIL

Code: Select all

METHOD CASEConvert( nValue ) CLASS TEXTBOX

   IF PCOUNT() == 0
      RETURN ::nValue
   ELSEIF PCOUNT() == 1
      ::nCaseConvert := nValue
   ENDIF

   RETURN NIL

Sorry, but this code has an error in the RETURN ::nValue...

Re: Uppercase in textbox (HMG4)

Posted: Tue Aug 02, 2011 11:22 am
by pctoledo
Correct, it is true:

Code: Select all

METHOD CASEConvert( nValue ) CLASS TEXTBOX

   IF PCOUNT() == 0
      RETURN ::nCaseConvert
   ELSEIF PCOUNT() == 1
      ::nCaseConvert := nValue
   ENDIF

   RETURN NIL

Code: Select all

METHOD MaxLength( nValue ) CLASS TEXTBOX

   IF PCOUNT() == 0
      RETURN ::nMaxLength
   ELSEIF PCOUNT() == 1
      ::nMaxLength := nValue
   ENDIF

   RETURN NIL
Sorry!

Re: Uppercase in textbox (HMG4)

Posted: Wed Aug 03, 2011 9:36 am
by mrduck
Patch commited to svn

please check

Re: Uppercase in textbox (HMG4)

Posted: Wed Aug 03, 2011 11:15 am
by pctoledo
mrduck, need only change:

Code: Select all

   DATA nMaxLength                                INIT   0
Thanks!

Re: Uppercase in textbox (HMG4)

Posted: Wed Aug 03, 2011 1:01 pm
by mrduck
pctoledo wrote:mrduck, need only change:

Code: Select all

   DATA nMaxLength                                INIT   0
Thanks!

done, sorry