FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Get decimal picture
Posts: 389
Joined: Mon Oct 13, 2008 11:26 AM
Get decimal picture
Posted: Fri May 10, 2013 01:14 PM
Code (fw): Select all Collapse
Redefine Get      oGt[4];
         Var      cStr[5] ;
         Update;
         ID       108;
         Picture  "999,999.99" ;
         of       oDlg

         
Procedure ChangePicture()         
   cMascara := "999,999.999"
   oGt[4]:cPicture := cMascara
   oGt[4]:oGet:Picture := cMascara
   oGt[4]:Refresh()
Return

With this the picture is changed, but only if I press "." ( dot ) before the first decimal be filled I can add the third decimal.

Sample:
List of pressed keys
123.456 = OK     => 123.456
12345.678 = OK   => 12,345.678 
123456.789 = OK  => 123,456.789
123456789 = Fail => 123,456.780
1234567.89 = Fail => 123,456.790
12345678.9 = Fail => 123,456.790


In the TGet class I found this in the KeyChar method, I tried to implement this but with no success.

Code (fw): Select all Collapse
   if ::oGet:Type == "N" .and. ( Chr( nKey ) == "." .or. Chr( nKey ) == "," )
      if ::oGet:Clear()
         #ifndef __XHARBOUR__
            ::oGet:DelEnd()
         #endif
      endif

      ::oGet:ToDecPos()
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Get decimal picture
Posted: Fri May 10, 2013 02:01 PM

Try this:

Procedure ChangePicture()
cMascara := "999,999.99"
oGt[4]:cPicture := cMascara
oGt[4]:oGet:Picture := cMascara
oGt[4]:oGet:VarGet() // not sure about this one
oGt[4]:oGet:SetText( oGt[4]:oGet:buffer )

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 389
Joined: Mon Oct 13, 2008 11:26 AM
Re: Get decimal picture
Posted: Fri May 10, 2013 02:29 PM

Application

Path and name: C:\TRADE9\TradeNFe.EXE (32 bits)
Size: *** bytes
Time from start: 0 hours 0 mins 50 secs
Error occurred at: 10/05/2013, 11:28:12
Error description: Warning BASE/1004 Message not found: TCLIPGET:SETTEXT

Stack Calls

Called from: source\rtl\tobject.prg => TCLIPGET:ERROR(172)
Called from: source\rtl\tobject.prg => TCLIPGET:MSGNOTFOUND(205)
Called from: source\rtl\tobject.prg => TCLIPGET:SETTEXT(0)
Called from: G:\prog\fivewin\RCA Trade\Versao9.0\Source\DlgVenda.prg => DETALHEPRODUTO(17114)

oGt[4]:cPicture := cMascara
oGt[4]:oGet:Picture := cMascara
oGt[4]:oGet:VarGet() // not sure about this one
oGt[4]:oGet:SetText( oGt[4]:oGet:buffer ) //-- 17114

Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
Posts: 389
Joined: Mon Oct 13, 2008 11:26 AM
Re: Get decimal picture
Posted: Fri May 10, 2013 02:34 PM

oGt[4]:oGet:SetText( oGt[4]:oGet:buffer ) //-- 17114
oGt[4]:SetText( oGt[4]:oGet:buffer ) //-- Fixed the error, but still don't work properly

Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
Posts: 117
Joined: Tue Jan 03, 2006 06:18 PM
Re: Get decimal picture
Posted: Fri May 10, 2013 06:13 PM

Dear Sambomb

Try

Procedure ChangePicture()
cMascara := "999,999.999"
oGt[4]:cPicture := cMascara
oGt[4]:oGet:Picture := cMascara
oGt[4]:setfocus()
oGt[4]:Refresh()
Return

Regards,
kok

Posts: 389
Joined: Mon Oct 13, 2008 11:26 AM
Re: Get decimal picture
Posted: Fri May 10, 2013 06:37 PM

Kok, I change the picture in the valid of a get before this get, so I don't need to Set the focus on the Get since it is already here and if I use the SetFocus() I'll have a new trouble.

oGt[3]:bValid call the ChangePicture() when the focus go to the oGt[4]
The ChangePicture() in the sample is simplified to focus on the problem, but instead of cMascara := "999,999.999" I test what picture I need to use and define in the var.

Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
Posts: 389
Joined: Mon Oct 13, 2008 11:26 AM
Re: Get decimal picture
Posted: Mon May 13, 2013 02:43 PM

Anyone else has a guess?

Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Get decimal picture
Posted: Mon May 13, 2013 03:42 PM

Your error seems to be with the clipboard object, and I am not sure why there is a clipboard object.

Perhaps you can build a small self-contained sample program that shows the problem?

Regards,
James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 368
Joined: Sun May 31, 2009 06:25 PM
Re: Get decimal picture
Posted: Mon May 13, 2013 04:03 PM
Have a look at this
Code (fw): Select all Collapse
#include "fivewin.ch"

FUNCTION TEST
LOCAL aGets := array(2)
LOCAL aVars := { "999,999.999", 1234.567 }
LOCAL oDlg

DEFINE DIALOG oDlg RESOURCE "dlgtest"
    REDEFINE GET aGets[ 1 ] VAR aVars[ 1 ]  ID 101 OF oDlg VALID ChangePicture( aGets, aVars )
    REDEFINE GET aGets[ 2 ] VAR aVars[ 2 ] PICTURE aVars[ 1 ] ID 102 OF oDlg
ACTIVATE DIALOG oDlg
RETURN NIL

FUNCTION ChangePicture( aGets, aVars )         
   aGets[ 2 ]:oGet:Assign()
   aGets[ 2 ]:oGet:Picture := aVars[ 1 ]
   aGets[ 2 ]:oGet:UpdateBuffer()
   aGets[ 2 ]:Refresh()
RETURN .T.


tstget.rc
Code (fw): Select all Collapse
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
dlgtest DIALOG 0, 0, 186, 95
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "Ms Shell Dlg"
{
    DEFPUSHBUTTON   "OK", IDOK, 129, 7, 50, 14
    PUSHBUTTON      "Cancel", IDCANCEL, 129, 24, 50, 14
    EDITTEXT        101, 5, 21, 72, 14, ES_AUTOHSCROLL
    EDITTEXT        102, 5, 46, 93, 14, ES_AUTOHSCROLL
}
Regards,



André Dutheil

FWH 13.04 + HB 3.2 + MSVS 10
Posts: 389
Joined: Mon Oct 13, 2008 11:26 AM
Re: Get decimal picture
Posted: Mon May 13, 2013 07:50 PM
James

Code (fw): Select all Collapse
****************************************************************************
FUNCTION Teste()
****************************************************************************

Local oDlgMsg
Private oGet := Array(2), cGet := Array(2)

   cGet[1] := Space(10)
   cGet[2] := 1

   DEFINE DIALOG  oDlgMsg;
          FROM    10, 20 TO 20, 60;
          TITLE   "Test";
          Of      oWnd

   @ 1.6,  2.0 GET      oGet[1];
               Var      cGet[1];
               picture  "@!";
               SIZE     80, 12;
               OF       oDlgMsg;
               Valid    ChangePicture()

   @ 2.6,  2.0 GET      oGet[2];
               Var      cGet[2];
               picture  "99,999.99";
               SIZE     80, 12;
               OF       oDlgMsg

   @ 3.6, 14.0 ButtonBmp;
               SIZE      45, 13;
               ACTION    oDlgMsg:End();
               OF        oDlgMsg;
               TEXTRIGHT;
               prompt    "Exit"

   oDlgMsg:lHelpIcon := .f.

   ACTIVATE DIALOG oDlgMsg CENTERED
   
RETURN nil
/*------------------------------------------------------------------------*/

Function ChangePicture()
Local cPicture := "99,999.999"

   oGet[2]:cPicture := cPicture
   oGet[2]:oGet:Picture := cPicture
   oGet[2]:Refresh()
   
Return  .T.


Tab to change the GET and then try to fill the second get with: 12345678 => must return 12,345.670 instead of the desirable 12,345.678.
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
Posts: 389
Joined: Mon Oct 13, 2008 11:26 AM
Re: Get decimal picture
Posted: Mon May 13, 2013 07:56 PM
I found a workaround:

Code (fw): Select all Collapse
/*------------------------------------------------------------------------*/
   oGt[4]:cPicture := cMascara
   oGt[4]:oGet:Picture := cMascara
   
   //-- Remover o valid do controle atual para poder executar o pause()
   oBackupDlg := ActiveDialog()
   
   bBackupValid := "NAOPRECISA"
   
   //-- Identificar qual o controle que está com o foco
   For i := 1 to Len( oBackupDlg:aControls )
   
      If oBackupDlg:aControls[i]:lFocused

         //-- Obter o valid antigo
         Try
            bBackupValid := oBackupDlg:aControls[i]:bValid
            oBackupDlg:aControls[i]:bValid := {||SysRefresh()}
         Catch
            bBackupValid := "NAOPRECISA"
         End
         
         Exit
         
      End
   
   End
   
   Pause(0.1,.T.)//-- Create another dialog 
   
   //--Restaurar o valid
   If ValType(bBackupValid) = "B" //-- Só é bloco se passar encontrar um objeto válido

      oBackupDlg:aControls[i]:bValid := bBackupValid
      
   End
   
   oGt[4]:Refresh()
/*------------------------------------------------------------------------*/

****************************************************************************
procedure Pause( nSeconds , lRefresh)
****************************************************************************

local oDlgPause, bAction
local nStart := GetTickCount()
local oDlgDef := GetWndDefault()

   Default nSeconds := 1, lRefresh := .f.

   if .not. lRefresh

      while GetTickCount() - nStart < ( 1000 * nSeconds )
         SysRefresh()
      end

   else
      bAction := { || WaitSeconds( nSeconds ) }

      DEFINE DIALOG     oDlgPause                       ;
             FROM       -10,-10 TO 1, 1                 ;
             STYLE      nOr( DS_MODALFRAME, WS_POPUP )  

      oDlgPause:nTop := -20
      oDlgPause:nLeft := -20

      oDlgPause:bStart := { || Eval( bAction, oDlgPause ),  oDlgPause:End(), SysRefresh() }

      ACTIVATE DIALOG oDlgPause

   end

Return NIL

/*------------------------------------------------------------------------*/
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
Posts: 389
Joined: Mon Oct 13, 2008 11:26 AM
Re: Get decimal picture
Posted: Fri May 17, 2013 11:09 AM

Antonio, James, Kok?

Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Get decimal picture
Posted: Fri May 17, 2013 02:22 PM
Samir,

You need to add the UPDATE clause to the second GET.

Code (fw): Select all Collapse
   @ 2.6,  2.0 GET      oGet[2];
               Var      cGet[2];
               picture  "99,999.99";
               SIZE     80, 12;
               OF       oDlgMsg;
               UPDATE                      // add this


Regards,
James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Get decimal picture
Posted: Fri May 17, 2013 03:56 PM
Mr Samir
The code you posted in your first post itself is working well for me, in the sense that the picture is changed and the new picture is functioning successfully.
This is the simple program I tested.
Code (fw): Select all Collapse
function GetPic()

   local n1 := 0, n2 := 1.234
   local aGet[ 2 ]
   local oDlg


   DEFINE DIALOG oDlg SIZE 200,200 PIXEL

   @ 10,10 GET aGet[ 1 ] VAR n1 PICTURE "999,999.99" SIZE 60,12 PIXEL OF oDlg RIGHT ;
      VALID ChangePic( oDlg, aGet )
   @ 30,10 GET aGet[ 2 ] var n2 PICTURE "999,999.99" SIZE 60,12 PIXEL OF oDlg RIGHT ;
      VALID ( oDlg:Update(), .t. )
   @ 50,10 SAY n2 PICTURE "999,999.9999" SIZE 60,10 PIXEL OF oDlg UPDATE
   @ 70,10 BUTTON "OK" SIZE 30,14 PIXEL OF oDlg ACTION MsgInfo( Transform( n2, "999,999.9999" ) )

   ACTIVATE DIALOG oDlg CENTERED

return nil

//----------------------------------------------------------------------------//

static function ChangePic( oDlg, aGet )

   WITH OBJECT aGet[ 2 ]
      if !( ".999" $ :cPicture )
         :cPicture := ;
         :oGet:picture := "999,999.999"
         :Refresh()
      endif
   END

return .t.

The logic is exactly the same as yours in the first posting.
Initially the picture of the second get is set to 2 dec. places.
The valid clause of the first get changes the picture of second get to 3 dec.places.

After the valid clause changes the picture of second get, I observed that the second get is behaving exactly the same way as if the changed picture was set originally.

This is the screen shot initially. First get has input focus.


Entered some value in the first get and the focus shifted to second get. We can now see that the picture is changed successfully and see the value with 3 decimal places.


You said:
With this the picture is changed, but only if I press "." ( dot ) before the first decimal be filled I can add the third decimal.
.....
.....
123456789 = Fail => 123,456.780

What I observed is different.
I now entered 123456789.
This is the result:


In this case result of entering
123456789 = success = 123,456.789.

I tested with both Harbour and xHarbour and latest FWH.

You have also observed:
1234567.89 = Fail => 123,456.790
12345678.9 = Fail => 123,456.790

Actually pressing decimal after the cursor moves post decimal place is not common. After digits 123456 are entered the Get automatically moves the cursor to the right of the decimal place. After entering one digit and then press "." the behaviour is different in Harbour and xHarbour.

If we are not agreeable with the behaviour of what happens when we press '.' after crossing the decimal point, that has nothing to do with dynamically changing the picture. What I can definitely say is that it is the same behaviour whether the 3 decimal picture was originally specified or dynamically changed during program execution.

In my view, your original code was adequate to successfully change the picture. There is no need to keep on trying different alternatives. If you find that it does not, then may be it is an issue with the versions you are using.
Regards



G. N. Rao.

Hyderabad, India
Posts: 389
Joined: Mon Oct 13, 2008 11:26 AM
Re: Get decimal picture
Posted: Fri May 17, 2013 07:34 PM
James thx for the reply, I forgot the update clause only in the sample, in my code the Update is defined.

Code (fw): Select all Collapse
   cStr[4] := 0
   Redefine Get       oGt[4]                                ;
            var       cStr[4]                               ;
            Update                                          ;
            ID        107                                   ;
            of        oDlg                                  ;
            when      .not. Empty(cStr[3])                  ;
            Message   "Informe a quantidade a ser faturado"
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2