Page 1 of 1
Wish: Function to show any type of data
Posted: Fri Dec 19, 2008 1:40 pm
by sambomb
A function that acts like Alert() but show:
Objects(name, type)
String(value,len,OEM/ANSI)
Numeric(value)
Date(value)
Array(value of each data, even if multidimensional)
Null(show a message tha it's nil with a different color)
I think that it can be done easily and will give a help to many developpers.
Posted: Fri Dec 19, 2008 1:59 pm
by Antonio Linares
Samir,
You can use MsgInfo( uValue ), or MsgAlert( uValue ), or MsgStop( uValue ).
Also you have cValToChar( uValue ) that converts any value to a string.
Posted: Fri Dec 19, 2008 3:46 pm
by sambomb
Antonio, some of these functions returns the value of multidimensional array?
Posted: Tue Dec 23, 2008 11:28 am
by Antonio Linares
No, you have to code it by yourself, using a browse or a tree, or building a string yourself.
Those functions will show "Array".
Posted: Tue Dec 23, 2008 5:50 pm
by sambomb
If I ain't wrong, some of these functions don't accept null too....
I im thinking in a universal function to show values, maybe a upgrade in the functions or a new function....
I know that I can do it myself, but I'm not thinking only im me...
It will help me to avoid add a procedure at each project only.
Thanks, merry christmas and happy new year!
Posted: Tue Dec 23, 2008 5:54 pm
by Maurizio
Hello
you have to try in fwh\samples\insptest.prg ( from older version of FW )
it works to inspect array and object
Regards MAurizio
Posted: Tue Dec 23, 2008 6:46 pm
by sambomb
Maurizio, is something like that but why not change the actual functions to do this?
or add a procedure: Analyse( uVar )
that send message( like Alert(), Msg() ) with the type of the data(in the title) and the value.
All I want is to group already done functions to a better result.
Re: Wish: Function to show any type of data
Posted: Mon Dec 29, 2008 2:27 am
by Marcelo Via Giglio
Hello,
you can start with this tiny example, and extend for other data types
Code: Select all
#include "FiveWin.ch"
#include "xbrowse.ch"
function Main()
viewdata( {"a","b","c", {"A","B","C", {1,"2", DATE() } } } )
return nil
//----------------------------------------------------------------------------//
FUNCTION viewdata( data )
//----------------------------------------------------------------------------//
IF VALTYPE( data ) = "A"
viewarray( data )
ELSE
msginfo( data )
ENDIF
RETURN NIL
//----------------------------------------------------------------------------//
STATIC FUNCTION viewarray( aArray )
//----------------------------------------------------------------------------//
LOCAL oBrw, oDlg, aData := {}, i
FOR i := 1 TO LEN( aArray )
DO CASE
CASE valtype( aArray[i] ) = "D" ; AADD( aData, {i, "D", DTOC( aArray[i] ) } )
CASE valtype( aArray[i] ) = "N" ; AADD( aData, {i, "N", STR( aArray[i] ) } )
CASE valtype( aArray[i] ) = "L" ; AADD( aData, {i, "L", IF( aArray[i], ".T.", ".F." ) } )
CASE valtype( aArray[i] ) = "C" ; AADD( aData, {i, "C", aArray[i] } )
CASE valtype( aArray[i] ) = "A" ; AADD( aData, {i, "A", "ARRAY" } )
ENDCASE
NEXT
DEFINE DIALOG oDlg FROM 1,1 TO 20,28
@ 0,0 XBROWSE oBrw ;
OF oDlg ;
ARRAY aData ;
HEADERS "Ind", "Tipo", "Valor" ;
JUSTIFY .T., 2, .F.;
COLSIZES 30,30,100 ;
AUTOCOLS ;
ON CHANGE oDlg:aEvalWhen()
oBrw:lHScroll := .F.
oBrw:lVScroll := .T.
oBrw:nMarqueeStyle := 5
oBrw:nRowHeight := 20
oDlg:oClient := oBrw
oBrw:CreateFromCode()
@ 7,01 BUTTON "Array" OF oDlg WHEN aData[ oBrw:nArrayAt, 2 ] == "A" ACTION viewarray( aArray[oBrw:nArrayAt] )
@ 7,12 BUTTON "Salir" OF oDlg ACTION oDlg:end()
ACTIVATE DIALOG oDlg ON INIT oBrw:SetFocus()
RETURN NIL
regards
Marcelo
Re: Wish: Function to show any type of data
Posted: Fri Dec 18, 2009 6:27 pm
by nageswaragunupudi
Now
XBrowse( <anydatatype> )
works
Re: Wish: Function to show any type of data
Posted: Mon Dec 21, 2009 1:43 am
by hua
Samir,
I find ValToPrg() helps me a lot in my debugging. It's a function in xHarbour. I normally use it to inspect arrays