Page 1 of 2

dget/getid

Posted: Sun Jan 08, 2017 4:59 am
by Zdeno Bielik
Hi Roger,

please, can you add support for CodeBlock in GETID clause of DCGET like it exists for COLOR clause?

I need create GETID names at runtime, because unique ID I need in custom handler,
where I want set to corresponding object after pressing(some next actions/calculatings are done too) any possible „defined“ hotkeys.

Code: Select all

For i := 1 To Len( M->paTabulkaNew )
    nRow++

    cValid := '{ || MG_V8( ' + AllTrim( Str( i ) ) + '), MG_TestKV( M->paTabulkaNew, M->pnVolneSkup, GetList ) }'
    bValid := &( cValid )

    cGetID := '{ || CreateGetID_Name( ' + AllTrim( Str( i ) ) + ' ) }'
    bGetID := &( cGetID )

    @ nRow, 1 DCSAY AllTrim(M->paTabulkaNew[i,1])+' - '+AllTrim(M->paTabulkaNew[i,2]) SAYSIZE 14   SAYRIGHT  PARENT oSt_Vst
    @ nRow,18 DCGET M->paTabulkaNew[i,6] PICTURE '99' RANGE 0,99 ;     
                VALID bValid ;
                GETID bGetID ;  
                LOSTFOCUS { || DC_GETREFRESH( GetList, nil, DCGETREFRESH_ID_EXCLUDE, { 'GET_EXPO_CISLO', 'GET_CAS', 'BROWSER' } )
, DC_DebugBrowse( { M->paTabulkaNew }, {"M->paTabulkaNew"}, , , ,  , ,  ) } PARENT oSt_Vst
Next
...

Code: Select all

********************************
Function CreateGetID_Name( _i )
********************************

Local cGetName := ''

wtf _i

cGetName := ( 'GET_F' + PadL( AllTrim( Str( _i, 2 ) ), 2, '0' ) )
wtf cGetName

Return ( cGetName )

*

Many thanks.

Zdeno



COLOR | GETCOLOR <ncFGc>, <ncBGc> are foreground and background
colors. They may be character strings representing valid text-based
colors supported by SetColor() or they may be numeric constants
which begin with either the prefix GRA_CLR_ or the prefix
XBPSYSCLR_ as defined in GRA.CH or XBP.CH. If <bncFGc> is a
code block is must return a 2-element array containing a
foreground and background color.


GETID <cId> is a unique identifier for this object. This ID is used
with functions like DC_GETORIGUPDATED() to determine the status
of a get object.

Re: dget/getid

Posted: Mon Jan 09, 2017 8:16 am
by rdonnay
I don't understand why you think you need a code block.
The below code should work for you.

If you need to know the ID of an object later in the code, you can get it by using CARGO:

cGetId := DC_GetCargo(oGet)

Also I recommend using WTF instead of DC_DebugBrowse(). It is much simpler.

Code: Select all

For i := 1 To Len( M->paTabulkaNew )
    nRow++

    cValid := '{ || MG_V8( ' + AllTrim( Str( i ) ) + '), MG_TestKV( M->paTabulkaNew, M->pnVolneSkup, GetList ) }'
    bValid := &( cValid )

    cGetID := CreateGetID_Name(AllTrim( Str( i ) ) ) 

    @ nRow, 1 DCSAY AllTrim(M->paTabulkaNew[i,1])+' - '+AllTrim(M->paTabulkaNew[i,2]) SAYSIZE 14   SAYRIGHT  PARENT oSt_Vst
    @ nRow,18 DCGET M->paTabulkaNew[i,6] PICTURE '99' RANGE 0,99 ;     
                VALID bValid ;
               GETID cGetID ;  
                CARGO cGetID ;
                LOSTFOCUS { || DC_GETREFRESH( GetList, nil, DCGETREFRESH_ID_EXCLUDE, { 'GET_EXPO_CISLO', 'GET_CAS', 'BROWSER' } )
, ( wtf M->paTabulkaNew) } PARENT oSt_Vst
Next

Re: dget/getid

Posted: Mon Jan 09, 2017 9:18 am
by Zdeno Bielik
Roger,

thanks for tips, but I am not sure, if it will works for me.
I don’t need detect cID of any GetObject, but I need get/know pointer to GetObject or Name/cID of GetObject.

Please, just look at short version of my custom-handler
cID := M->paTabulkaNew[ nPosFx, 2 ]
wtf cID
SetAppFocus( DC_GETOBJECT( GetList, cID ) )
so, if I want use that code, I must have defined unique cID for each GetObject
and I don’t know, how many gets will be created and what items(with different names/parameters…) will be used as source-data

Code: Select all

DCREAD HANDLER My_Handler01 REFERENCE GetList …
...

Code: Select all

******************************
Static FUNCTION My_Handler01( nEvent, mp1, mp2, oXbp, oDialog, GetList, /*aLocal*/ aApp )        
******************************

Local nPosFx, nPosCtrlFx

If ( nEvent == xbeP_Keyboard )
*    wtf mp1

   nPosFx     := AScan( M->paTabulkaNew, { | x | x[ 3 ] == mp1 } )
   nPosCtrlFx := AScan( M->paTabulkaNew, { | x | x[ 4 ] == mp1 } )
*    wtf nPosFx, nPosCtrlFx

   If ( nPosFx > 0 )

*        wtf M->paTabulkaNew[ nPosFx, 6 ]

       If ( M->paTabulkaNew[ nPosFx, 6 ] <= 98 )
          M->paTabulkaNew[ nPosFx, 6 ] ++
       EndIf
*        wtf M->paTabulkaNew[ nPosFx, 6 ]

       M->paTabulkaNew[ nPosFx, 8 ] := ( M->paTabulkaNew[ nPosFx, 6 ] * M->paTabulkaNew[ nPosFx, 7 ] )
*        wtf M->paTabulkaNew[ nPosFx, 8 ]

*        SetAppFocus( DC_GETOBJECT( GetList, 'GET_F02' ) )
*        SetAppFocus( DC_GETOBJECT( GetList, 'GET_EXPO_CISLO' ) )

       cID := M->paTabulkaNew[ nPosFx, 2 ]
       wtf cID 
       SetAppFocus( DC_GETOBJECT( GetList, cID ) )

       DC_GETREFRESH( GetList, nil, DCGETREFRESH_ID_EXCLUDE, { 'GET_EXPO_CISLO', 'GET_CAS', 'BROWSER' } )



    ElseIf ( nPozCtrlFx > 0 )

*        wtf M->paTabulkaNew[ nPosCtrlFx, 6 ]
       If ( M->paTabulkaNew[ nPosCtrlFx, 6 ] >= 1 )
          M->paTabulkaNew[ nPosCtrlFx, 6 ] --
       EndIf
*        wtf M->paTabulkaNew[ nPosCtrlFx, 6 ]
       M->paTabulkaNew[ nPosCtrlFx, 8 ] := ( M->paTabulkaNew[ nPosCtrlFx, 6 ] * M->paTabulkaNew[ nPosCtrlFx, 7 ] )
*        wtf M->paTabulkaNew[ nPosCtrlFx, 8 ]

       cID := M->paTabulkaNew[ nPosCtrlFx, 2 ]
       wtf cID 
       SetAppFocus( DC_GETOBJECT( GetList, cID ) )

       DC_GETREFRESH( GetList, nil, DCGETREFRESH_ID_EXCLUDE, { 'GET_EXPO_CISLO', 'GET_CAS', 'BROWSER' } )


* If ( nTemp != 0 )

*        wtf M->paTabulkaNew[ 1,6]

*                             /*3*/ VK_xbe( aCennik[ix,4] /*'F1'*/ ), ;
*                             /*4*/ VK_xbe( 'CTRL_' + aCennik[ix,4] /*'CTRL_F1'*/ ), ;
*                  { 'F1'      , xbeK_F1       }, ;
*                  { 'CTRL_F1' , xbeK_CTRL_F1  }, ;


   EndIf

Else

* mouse events…

EndIf

RETURN DCGUI_NONE

*

Re: dget/getid

Posted: Mon Jan 09, 2017 9:58 am
by rdonnay
I really don't know what you are trying to do. It's very confusing, looking at your code.

Re: dget/getid

Posted: Mon Jan 09, 2017 11:36 am
by Zdeno Bielik
each array’s item has few values, e.g. name, value, HotKey for increase value, HotKey for decrease value, etc. …

so, e.g. if user press HotKey defined for increasing value for needed array-item, its value is incresed and GetList(whole or just needed get-objects) is refreshed
but I also want/need set cursor into that DCGET object whom value was increased or decreased

is this more understandable now? so, please, is it possible add asked behaviour for me?

something like this may work:

Code: Select all

IF Valtype(cID) = 'B'
    cID := Eval(cID)
ENDIF
I think you added some similar funcionality for someone recently, but I not sure for what clause

Re: dget/getid

Posted: Mon Jan 09, 2017 12:58 pm
by rdonnay
Supporting a code block for an ID will require changing a lot of code.
That will require a long beta-testing period to make sure it doesn't break existing applications.

You should look at using CARGO. It will accept any data type.

Re: dget/getid

Posted: Tue Jan 10, 2017 4:31 am
by Zdeno Bielik
hmmm, I know, some changes may need more times, but if I do not add asked funcionality to end-customer, I will lost him...
last asked „little change“ (from him point of view) did take me more than 4 months time and requires completly redisign many functions, databases, logic, reports...

please, how can CARGO and then DC_GetCargo() help me solve situation?
DC_GetCargo() needs oGetObjectName as parameter, but if dcget object is generated during runtime,
I can not assign any wanted GETOBJECT cName variable/text, because this clause does not support CodeBlock too
so I don’t know for what oGetObject I must to reference(use as parameter)

and if I will know oGetName of DCGET objects created at runtime,
then there is no problem to set focus to wanted oGetName via SetAppFocus()
and I will don’t need use Cargo/DC_GetCargo() – or am I wrong?

Re: dget/getid

Posted: Tue Jan 10, 2017 5:45 am
by reganc
Zdeno

I think I understand what you are trying to do.

In the handler you are reacting to a hotkey that is contained in the paTabulkaNew array.
You find the array element the hotkey is related to by using an ascan. This allows you to increase or decrease the value in that array. You do a dc_getrefresh to update the value onscreen. You also want to put the focus into the get field.

That last bit is where you are having trouble.

Did you try adding a GETOBJECT clause to each DCGET that puts the object reference into the paTabulkaNew array as the screen is displayed? Is there some reason you cannot do that? Or did you try and were not able to get that working?

Did you try using the 'name' element value as the GETID?

Re: dget/getid

Posted: Tue Jan 10, 2017 7:34 am
by rdonnay
Did you try adding a GETOBJECT clause to each DCGET that puts the object reference into the paTabulkaNew array as the screen is displayed?
Regan has a good idea here:

Code: Select all

    @ nRow,18 DCGET M->paTabulkaNew[i,6] PICTURE '99' RANGE 0,99 ;     
                VALID bValid ;
                GETID bGetID ;  
                GETOBJECT M->paTabulkaNew[i,9] ;  <<<<<<<<<<<<<<<<<<<<<<<<
                LOSTFOCUS { || DC_GETREFRESH( GetList, nil, DCGETREFRESH_ID_EXCLUDE, { 'GET_EXPO_CISLO', 'GET_CAS', 'BROWSER' } )

Re: dget/getid

Posted: Tue Jan 10, 2017 9:18 am
by Zdeno Bielik
Regan, Roger,

thanks for tip, but attempts with GETOBJECT clause were first.
After unsuccessfull tests I started play with GETID clause.

Code: Select all

* cGetObject := '{ || "oGet' + PadL( AllTrim( Str( ix, 2 ) ), 2, '0' ) + '" }'
* cGetObject := '{ || oGet' + PadL( AllTrim( Str( ix, 2 ) ), 2, '0' ) + ' }'

cGetObject := '{ || CreateGetObjectName( ' + AllTrim( Str( ix ) ) + ' ) }'
bGetObject := &( cGetObject )
if I used GETOBJECT bGetObject ;
or now GETOBJECT M->paTabulkaNew[ix,5] ; && value is e.g. ‘GET_01’

later in both variants program crash at SetAppFocus

Code: Select all

cID := M->paTabulkaNew[ nPozFx, 5 ]            
wtf cID pause
SetAppFocus( DC_GetObject( GetList, cID ) )      

Code: Select all

oError:args         :
         -> VALTYPE:U VALUE:NIL
oError:canDefault   : .F.
oError:canRetry     : .F.
oError:canSubstitute: .T.
oError:cargo        : NIL
oError:description  : Parameter has a wrong data type
oError:filename     : 
oError:genCode      : 2
oError:operation    : setAppFocus

Code: Select all

********************************
Function CreateGetObject_Name( _i )
********************************

Local cGetName := ''

wtf _i

cGetName := ( 'GET_F' + PadL( AllTrim( Str( _i, 2 ) ), 2, '0' ) )
wtf cGetName

Return ( cGetName )

*
like I wrote before it looks GETOBJECT clause does not support codeblock too.

OBJECT | GETOBJECT <oObject> is the variable to use as a container
for the object after it is created by the GUI reader.