Page 1 of 1

Clase Tget y su Picture

PostPosted: Tue Dec 18, 2007 12:39 pm
by fgondi
En la clase tget me he encontrado el siguiente problema:

Un get definido con un picture '@KE 9,999.999' por ejemplo
Introducimos en él el valor 1200.67453, oGet:cText( 1200.67453), osea un valor con mas decimales de los que se van a mostrar en el picture.

El dato es visualizado correctamente y al volver a obtener el contenido del get, Eval(oGet:bSetGet), muestra 1200.67453

Pero si pasan por el campo sin editar nada, osea se posicionan en el get y pulsan intro sin haber alterado nada, el bsetget cambia y se obtiene 1200.675 (el valor pasado por el transform). Acabo de perder el contenido real del get sin que el usuario haya alterado los datos.

Yo lo he solucionado de esta forma:
Code: Select all  Expand view
CLASS TGet FROM TControl

   DATA   xPrevio  //... Nuevo.fgondi
   ....
   METHOD SetxPrevio( xText )  //... Nuevo.fgondi
   ...

   METHOD New(...)  CLASS TGet
   ...
   ::SetxPrevio( Eval(::bSetGet) )  //... Nuevo.fgondi
   return Self

   METHOD Redefine(...)  CLASS TGet
   ...
   ::SetxPrevio( Eval(::bSetGet) )  //... Nuevo.fgondi
   return Self

   Method cText( cText ) Class TGet
  ::SetxPrevio( cText )  //... Nuevo.fgondi
  ....

  METHOD lValid() CLASS TGet
  local lRet := .t.
  ::SetxPrevio( Eval(::bSetGet) )  //... Nuevo.fgondi
  ...

  METHOD SetxPrevio( xText )   //... Nuevo.fgondi
  local xCaption
  if ::xPrevio==NIL
    ::xPrevio := xText
    return self
  endif
  if ::cPicture<>nil .and. Valtype(::xPrevio)==Valtype(xText)
    xCaption := Transform( ::xPrevio, ::cPicture )
    if Valtype(xText)='N'
      xCaption := StrTran( xCaption, '.', ''  )
      xCaption := StrTran( xCaption, ',', '.'  )
      xCaption := Val(xCaption)
    endif
    if !::xPrevio==xText .and. xCaption==xText
      ::cText( ::xPrevio )
    else
      ::xPrevio := xText
    endif
  endif
  return self