Complex2Buffer - Create a buffer string from complex data

 

Top 

Syntax

<bufferData> := Complex2Buffer( <anyData>, [<lDontConvertSimpleTypes>], [<nStringType>] )

Parameters

<anyData>

 

The data to be assembled in a data buffer, normally an array. This buffer can be passed to an API function requesting the pointer to some data.

 

<lDontConvertSimpleTypes>

 

This flag controls the handling of 'simple' data types. This flag will normally be .T. (which is the default) when Complex2Buffer is called from a program. This is the table of simple types for <anyData> and the values returned for them if this flag is .T.:

 

Numeric

The value passed in <anyData> is returned

Object

The member :handle is returned, if it is a fake object.

Logical

0 (FALSE) is returned for .F., 1 (TRUE) is returned for .T.

Undefined

If the value NIL is passed, 0 is returned

 

<nStringType>

 

This parameter's value determines the treatment of all strings contained in <anyData>. See Cockpit string types for details. The default is STRINGTYPE_BINARY.

Return value

A string representing the data buffer created from the data passed in <anyData>.

Description

Complex2Buffer creates a data buffer from complex data passed in. This passed in data can be a mixture of strings, structures, numeric values, logicals or objects in linear and nested arrays. Arrays are traversed from first to last element, nested arrays are traversed as they are encountered. The result is a buffer string containing all data found traversing and converting <anyData>. If no special handling is requested (see the <lDontConvertSimpleTypes> parameter), the data found in <anyData> is stringified and added to the returned buffer string according to this table:

 

Data type

Conversion before addition to returned data buffer string

Numeric

Data is interpreted as LONG value and L2Bin is applied.

Character

Data is handled as requested in <nStringType>. See Cockpit string types for details.

Logical

The LONG value TRUE (1) or FALSE (0) is added to the data buffer after applying L2Bin.

Undefined (NIL)

The LONG value 0 is added to the data buffer after applying L2Bin.

Structure

The :buffer member var of the passed object is added to the data buffer after calling :Lock().

If the structure contains pointer members, the pointer data memory allocated by the call to :Lock() must be freed later on. This can be achieved by calling Buffer2Complex (if you want to retransfer changes made to the data buffer to <anyData>) or UnlockComplex (if no changes are to be retransferred to <anyData>) passing <anyData> later on.

Fake object

The :handle member var is added to the data buffer after applying L2Bin.

COM interface

The :baseAddress member var is added to the data buffer after applying L2Bin.

Array

Arrays are scanned from first to last element and the above conversions are applied to every element. If an Array element is another array, this array is scanned first before continuing in the containing array.

Classification

Core

Category

Array and string utility

Quick Info

Library: cckptcor.lib / cckptcor.dll

Header: StringTypes.ch

See also

Buffer2Complex, UnlockComplex

Example

 

#INCLUDE "CockpitCoreLibs.ch"

#INCLUDE "CockpitPlatformLibs.ch"  

#INCLUDE "StringTypes.ch"

 

FUNCTION Main

 

LOCAL complexdata

LOCAL rect := RECT():New()

LOCAL desktop := GetDesktopWindow()

LOCAL buffer, value

 

* Initialize the RECT structure

rect:left := 10

rect:top  := 20

rect:right := 30

rect:bottom := 40

 

* Set up some complex data. Please note that the RECT structure does not contain

* pointer members and hence we don't have to release any pointer memory with

* UnlockComplex or Buffer2Complex.

complexData := { 1, .T., NIL,  { rect, desktop }, "Test string" }

 

* Interpret the string as text and add a trailing Chr(0)

buffer := Complex2Buffer(complexdata) 

? "Buffer 1: ", HexString(buffer)

 

* Interpret the string as Unicode text and add two trailing Chr(0)s

buffer := Complex2Buffer(complexdata,,STRINGTYPE_UNICODETEXT) 

? "Buffer 2: ", HexString(buffer)

 

* Don't pack simple data, in this case 1 (the value of TRUE) will be returned

value := Complex2Buffer(.T.,.T.)                                             

? "Returned value: ", value

 

RETURN NIL