Page 1 of 1

Column Function in XBROWSE

PostPosted: Thu Oct 12, 2017 3:45 pm
by damianodec
hi to all,
I would Like a column in XBROWSE with result of function:
Code: Select all  Expand view

...
oRs := FW_OpenRecordSet( oCn, tuple, 1 )
@ 40,10 XBROWSE oBrw SIZE -10,-50 PIXEL ;
RECORDSET oRs ;
      COLUMNS "ONE", "TWO", "A", "B",  'MYFUNCTION(fieldC)' ;
      OF oDlg2 
....

FUNCTION MYFUNCTION(fieldC)
local x = 0
x = fieldc * x
return x
 

but in xbrowse I get costant MYFUNCTION(fieldC) in fifth column instead of x value.

any help?
thank you

Re: Column Function in XBROWSE

PostPosted: Thu Oct 12, 2017 5:28 pm
by Enrico Maria Giordano
Try removing the single quotes around the function.

EMG

Re: Column Function in XBROWSE

PostPosted: Fri Oct 13, 2017 7:00 am
by damianodec
hi Enrico, thank you for your help but if I remove single quote xbrowse goes in myfunction only one time.
I changed my prg:
Code: Select all  Expand view

...
oYORD := FW_OpenRecordSet( oCn, tuple, 1 )
oYORD:MoveFirst()

DEFINE DIALOG oDlg2 SIZE 800,500 PIXEL  FONT oFont;
STYLE nOR( DS_MODALFRAME, WS_POPUP, WS_CAPTION, WS_SYSMENU, ;
              WS_MAXIMIZEBOX, WS_MINIMIZEBOX, WS_THICKFRAME ) ;
              TITLE "ANALISI IMPLOSIONE: "+m_get[02]

@ 40,10 XBROWSE oBrw SIZE -10,-50 PIXEL ;
     RECORDSET oYord ;
  COLUMNS "LEVEL", "FIELD1", "FIELD2", "TIPO", "TIME", "PROGR", MRP00421(oYORD:Fields("FIELD1"):value,oCn) ;
  HEADERS "LIV", "BASE", "APERTO", "TIPO", "LEAD", "PROGR", "IN ORDINE" ;
  PICTURE "@ZE 999",,,,"@ZE 999", "@ZE 999" ;
  OF oDlg2 
...
Return NIL

*-----------------------------------------------------------------------------------
FUNCTION MRP00421(field, oCn)
local tuple, oRs
local totale := 0

msginfo(Field)

    tuple := +;
    "SELECT a.Totale as Totale..." +;
       etc...etc...etc...
    "WHERE ARTICOLO = '"+FIELD+"' AND WORKIT = 8 "
       etc... etc...

oRs := FW_OpenRecordSet( oCn, tuple, 1 )

if oRs:EOF()
    totale = 0.00
else
    oRs:MoveFirst()
    totale = oRs:Fields("Totale"):value
    msginfo(str(totale))
endif

oRs:Close()

Return Str(Totale)
 

I put MSGINFO into FUNCTION MRP00421 for check FIELD and it shows me msginfo only one time with NULL field.
the original RECORDSET oYord in XBROWSE had 25 rows and MRP00421 function should return calculate TOTALE (in another SELECT) for each row.
but COLUMN "IN ORDINE" in XBROWSE retrun 0,00 in each row

I have another my XBROWSE:
Code: Select all  Expand view

DEFINE DIALOG oDlg2 SIZE 800,500 PIXEL  FONT oFont;
    STYLE nOR( DS_MODALFRAME, WS_POPUP, WS_CAPTION, WS_SYSMENU, ;
              WS_MAXIMIZEBOX, WS_MINIMIZEBOX, WS_THICKFRAME ) ;
              TITLE "SCHEDA MOVIMENTI DI ACQUISTO FORNITORE: "+CDFOR

    @ 40,10 XBROWSE oBrw SIZE -10,-50 PIXEL ;
      RECORDSET oRsMovimenti ;
      COLUMNS 'dAAAAMMGGadata(DATA)',"CODICE","DESCR","RIFER","QTA","IMPORT","COSTO" ;
      HEADERS "DATA","CODICE","DESCRIZIONE","RIFERIM.","QUANTITA","IMPORTO","COSTO" ;
      PICTURE ,,,,"@ZE 99,999,999.999", "@ZE 99,999,999.999", "@ZE 99,999,999.999" ;

in this XBROWSE there is dAAAAMMGGadata FUNCTION whit single quotes that convert field DATA from YYYYMMDD to DD/MM/YYYY and it works for each row in oRsMovimenti

thank you

Re: Column Function in XBROWSE

PostPosted: Fri Oct 13, 2017 7:48 am
by Enrico Maria Giordano
Sorry, let's wait for Rao advice.

EMG

Re: Column Function in XBROWSE

PostPosted: Fri Oct 13, 2017 10:47 am
by Jack
Hi ,
When i have to do that, i insert a column and use a code block with my function :

oCol:=oLbxp:inscol(4)
oCol:bStrData:={||QSTOCK(oRsp:Fields("NB"):Value)}
oCol:cHeader:="Total"
*

*
function QSTOCK(p)
return p/2


Philippe .

Re: Column Function in XBROWSE

PostPosted: Fri Oct 13, 2017 1:13 pm
by Marcelo Via Giglio
Hola,

try to use a codeblock

Code: Select all  Expand view
oRs := FW_OpenRecordSet( oCn, tuple, 1 )
@ 40,10 XBROWSE oBrw SIZE -10,-50 PIXEL ;
RECORDSET oRs ;
      COLUMNS "ONE", "TWO", "A", "B",  {|| MYFUNCTION(fieldC)} ;
      OF oDlg2  
....

FUNCTION MYFUNCTION(fieldC)
local x = 0
x = fieldc * x
return x


But here we have a performance problem, because xBrowse repaint many time all the data

Regards

Marcelo

Re: Column Function in XBROWSE

PostPosted: Fri Oct 13, 2017 1:43 pm
by damianodec
hi thank you for your help
If I use codeblock, performance is very very slow.

I do not understand because If I use function 'dAAAAMMGGadata(DATA)' that works and with 'MRP00421(oYORD:Fields("FIELD1"):value,oCn)' not works

Re: Column Function in XBROWSE

PostPosted: Fri Oct 13, 2017 2:04 pm
by nageswaragunupudi
COLUMNS "ONE", "TWO", "A", "B", { || MYFUNCTION(fieldC) } ;

Re: Column Function in XBROWSE

PostPosted: Fri Oct 13, 2017 2:37 pm
by damianodec
thank you Mr.Rao
but is very slowly with codeblock.

why in a XBROWSE 'dAAAAMMGGadata(DATA)' works and 'MYFUNCTION(DATA1)' no ?

Re: Column Function in XBROWSE

PostPosted: Fri Oct 13, 2017 2:56 pm
by nageswaragunupudi
Speed depends purely on the implementation of the function.

why in a XBROWSE 'dAAAAMMGGadata(DATA)' works and 'MYFUNCTION(DATA1)' no ?


If the function is a public function ( i.e., not a static function ) and all parameters are either public/private or field variables, "MYFUNCTION(PARAMETERS)" works. In other words, XBrowse should be able to call the function with the parameters from inside xbrowse.

Otherwise, you need to use it as codeblock.

Re: Column Function in XBROWSE

PostPosted: Fri Oct 13, 2017 3:04 pm
by damianodec
thank you Mr Rao