Return a string representation of any passed expression
Stringify(<x>, [<nLevel>]) --> c
<x> is an expression of any XBase++ type. Any value that may be assigned to a variable may be passed to Stringify(). <nLevel> is used internally when recursive calls are made inside stringify. At a user-interface level, only the first parameter should be used.
Formatted string detailing the passed contents in human-readable form, including linebreaks, annotation, and indentation as appropriate. Since values allowing nesting (arrays and objects) may contain a large amount of data, the returned string will also potentially be of large size. Depending on the desired presentation and usage, it may be desirable to examine the return value with XBase++ standard string functions like LEN() and MLCOUNT() prior to final presentation.
For a number of purposes, it is useful to be able to produce a human-readable string representation of the contents of an expression. This is especially true of complex expression types like arrays and objects, since dates and numbers can be handled more easily by XBase++ standard functions. Furthermore, many occassions occur when it may not be known what value type an expression has before Stringify() is called -- either because of runtime modification of the type, or (from a developers perspective) because it is not yet understood what types are assigned to variables or fields.
When examining the content of an expression, Stringify() will call itself recursively if the passed expression is of an array or object type. There is no limitation on the depth of recursion executed by Stringify(). One particular use for Stringify() is in conjunction with children of Class Persistent, especially for Class Configuration, where structured information is written to disk in binary form. Stringify() allows translation of stored data structures to human-readable ASCII representations.
When representing an expression which is an object, the nature of the representation is dependent upon whether the object is a class that supports our introspection conventions. For a general class, such as one provided directly by XBase++, the detail Stringify() is able to generate is minimal, basically limited to the name of the class whose instance is Stringify()'d. However, where our instrospection mechanisms are implemented, full details of data members, including recursion where appropriate, are contained in the representation. The Debug class also makes use of the services of Stringify().
The best way to clarify the action of Stringify() is just to present the return values of a number of Stringify() calls. One moderately subtle point to notice in this output is the way numerics are handled. If a numeric value is a memory variable, it is left-padded to 10 characters to the left of the decimal (if any). However, when the numeric value is a DBF field, the padding (on both sides of the decimal) indicate the actual size definition of the field.
Stringify(XbpBitmap():new())
(obj)XbpBitmap No member data exposed for introspection No member methods exposed for introspection
Stringify(Configuration():new())
(obj)Configuration [Exposed member data] Font_Alert = 10.Arial ButtonLabels = .F. GrayBar = .F. ColorScheme = (obj)ColorScheme [Exposed member data] Activeborder = (numeric) -15 Passiveborder = (numeric) -14 Hilite = (numeric) -33 Shadow = (numeric) -32 Titlebar = (numeric) 4 Titletext = (numeric) -16 Statusbar = (numeric) 6 DialogBG = (numeric) 15 SchemeName = Compatibility Color Scheme [Exposed member methods] init Old Windows MY_Date = (date)10/03/99 savedCfg = .F. version = (numeric) 19990924 [Exposed member methods] init toDisk fromDisk antiquated verUpdate uptoDate
USE MYDBF NEW
Stringify(DbStruct())
[ARRAY(6)] 1. [ARRAY(4)] 1. HVENNO 2. N 3. (numeric) 6 4. (numeric) 0 2. [ARRAY(4)] 1. HINVNO 2. C 3. (numeric) 20 4. (numeric) 0 3. [ARRAY(4)] 1. HDUEDAT 2. D 3. (numeric) 8 4. (numeric) 0 4. [ARRAY(4)] 1. HREC 2. C 3. (numeric) 1 4. (numeric) 0 5. [ARRAY(4)] 1. HSC8 2. C 3. (numeric) 1 4. (numeric) 0 6. [ARRAY(4)] 1. HCHKAMT 2. N 3. (numeric) 11 4. (numeric) 2
Stringify(FIELDGET(1))
(numeric) 0
Stringify(3.1415)
(numeric) 3.1415
Stringify(DATE())
(date)10/03/99
Stringify("Hello World!")
Hello World!
// Build a data-dependent array, then verify contents
SELECT MyDBF
aComplex := {}
DO WHILE .NOT. EOF()
IF (MyDBF->Year > 1990)
AADD(aComplex, {MyDBF->Foo, MyDBF->Bar, "1990+"})
ELSEIF (MyDBF->Year > 1980)
AADD(aComplex, {MyDBF->Baz, "1980-1990"})
ELSE
AADD(aComplex, {MyDBF->Bar, SOME_CONSTANT, (MyDBF->Foo)/2 })
ENDIF
SKIP
ENDDO
// At this point we do not know how long aComplex is, nor the
// length or content of its subarrays. Let's verify visually.
? Stringify(aComplex)
Source file is string.prg
STR() - see XBase++ documentation
DTOC() - see XBase++ documentation
Var2Bin() - see XBase++ documentation