I developed an extended version of the MsgInfo function, is very useful for my to debug programs. This function is inspired by a similar function written by Esgici.
I hope you find it useful.
Best regards,
Claudio Soto.
Code: Select all
*******************************************************************************
* ARCHIVO: MsgInfoEx.prg
* LENGUAJE: HMG
* FECHA: Setiembre 2012
* AUTOR: Dr. CLAUDIO SOTO
* PAIS: URUGUAY
* E-MAIL: srvet@adinet.com.uy
* BLOG: http://srvet.blogspot.com
*******************************************************************************
#include "hbclass.ch"
#include <hmg.ch>
// #command MsgInfo(<arg1>,<arg2>) => hb_Alert(<arg1>)
//********************************************************************************************************
// MsgInfoEx (xMsg = [Array or xVar], [cSeparator], [cTitle], [bInfoDebug = .T.|.F.])
//********************************************************************************************************
FUNCTION MsgInfoEx (xMsg, cSeparator, cTitle, bInfoDebug)
LOCAL cMsg
cMsg := VarToStr (xMsg, cSeparator, bInfoDebug)
MsgInfo (cMsg, cTitle)
RETURN cMsg
//********************************************************************************************************
// VarToStr (Data = [Array or xVar], [cSeparator], [bInfoDebug = .T.|.F.])
//********************************************************************************************************
FUNCTION VarToStr (Data, cSeparator, bInfoDebug)
LOCAL i, text:="", nLen := 0
cSeparator := IF (ValType(cSeparator) == "U", " ", cSeparator)
bInfoDebug := IF (ValType(bInfoDebug) <> "L", .F., bInfoDebug)
IF ValType (Data) == "A"
nLen := LEN (Data)
text := text + IF (bInfoDebug, " { ", "")
FOR i = 1 TO LEN (Data)
text := text + VarToStr (Data [i], cSeparator, bInfoDebug) + IF (i < nLen, cSeparator,"")
NEXT
text := text + IF (bInfoDebug, " } ", "")
ELSEIF ValType (Data) == "B"
text := text + IF (bInfoDebug, " {|| ", "")
text := text + VarToStr (EVAL(Data), cSeparator, bInfoDebug)
text := text + IF (bInfoDebug, " } ", "")
ELSE
IF ValType (Data) == "C" .OR. ValType (Data) == "M"
text := text + Data
ELSEIF ValType (Data) == "D"
text := text + DTOC (Data)
ELSEIF ValType (Data) == "L"
text := text + IF (Data, ".T.",".F.")
ELSEIF ValType (Data) == "N"
text := text + ALLTRIM(STR(Data, 18, LENNUM(Data) - LENNUM(INT(Data)) -1))
ELSEIF ValType (Data) == "U"
text := text + "NIL"
ELSEIF ValType (Data) == "O"
text := text + "::Object::"
ELSE
text := text + "|Unknown Data|"
ENDIF
ENDIF
RETURN text
***************************************************************************************
* Example
***************************************************************************************
FUNCTION Main
SET DATE TO BRITISH
SET CENTURY ON
aWHITE := {255,255,255}
aBLACK := { 0, 0, 0}
aMat := {{aWHITE, aBLACK},;
{ 10, 20, 30, 40, 50},;
{{100, {"Hello", aWHITE, "HMG"}}, {200, 300, 400}},;
{{},NIL}};
MsgInfoEx ({"Desktop Width = ", GetDesktopWidth(), "Desktop Height = ", GetDesktopHeight()}, ,"Test1", .F.)
MsgInfoEx (aMat, ", " ,"Test2", .T.)
MsgInfoEx ({15, 20, date(), 23.5, "Hello", aBLACK, {10,12,aWHITE}, {||10*2+1}}, " , " ,"Test3", .T.)
MsgInfoEx ({13.9999, {|| 10 < 12}, NIL, aWHITE}, NIL ,"Test4")
MsgInfoEx (13.9999, NIL ,"Test5")
oTest := ClassTest()
oTest:GetSetValue (100)
oTest:lFlag := .T.
MsgInfoEx ({oTest, oTest:GetSetValue(), oTest:GetSetValue(200), oTest:lFlag, oTest:lFlag:=.F.}, " - ","Test6")
cMsg := VarToStr({oTest, oTest:GetSetValue(), oTest:lFlag, "Hello World", aWHITE, 21.33}, " , ", .T.)
MsgInfo (cMsg, "Test7")
RETURN
CLASS ClassTest
DATA Value INIT 0 PROTECTED
DATA lFlag INIT .F.
METHOD GetSetValue SETGET
ENDCLASS
METHOD GetSetValue (Arg) CLASS ClassTest
IF PCOUNT() == 0
RETURN ::Value
ELSE
::Value := Arg
ENDIF
RETURN