ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage syntax / 
  • Overview
  • Why use the Buffer type?
  • Buffer type: Syntax and use
  • Declaring a Buffer variable
  • Declaring and initializing a Buffer variable
  • Operations on a Buffer variable
  • 'Buffer on' type: Syntax and advanced use
  • Declaring a Buffer On variable
  • Operations on 'Buffer on' variables (called fixed buffers)
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Buffer (Type de variable)
Overview
The buffer type corresponds to a binary memory area.
With this type, a code that handles binary data can be shared between a WINDEV and a WINDEV Mobile application.
In WINDEV, a string variable can contain both characters and binary data (an image for example).
In WINDEV Mobile, if a character string variable contains binary data, this data may be corrupted (improper conversion for example). To handle binary data, it is recommended to use Buffer variables.
The buffer type does not have a specific end marker and allows you to store binary zeros.
Two types of variables are available:
  • Buffer: This type allows you to manage a memory area with a dynamic size: it is automatically adapted to the buffer content.
  • Buffer on: This type is used to handle a memory area whose size (in bytes) is defined during the compilation. This is an advanced type used to perform specific operations in memory, to use some Windows APIs.
Remark: Buffer variables are encoded in base64 in JSON and XML.
WEBDEV - Browser code In browser code, the Buffer type has multiple limitations: it is mostly used with BufferToHexa, and HexaToBuffer, Size and Hash functions.
Why use the Buffer type?
In WINDEV, the following code can be used to handle bytes as binary values:
S is string = Charact(1) + Charact(0)
The corresponding memory area is:
01

The same code has a different behavior if executed in Ansi or Unicode.
To have the same code in ANSI and in UNICODE, the string must be replaced with a buffer. The code becomes:
S is Buffer
S[[1]] = 1
S[[2]] = 0
Buffer type: Syntax and use

Declaring a Buffer variable

  • <Variable name> is Buffer
OR
  • <Variable name 1>, <Variable name 2> are Buffers
Details of syntax
<Variable name>:Name of the variable to declare.

Remark: By default, a Buffer variable is empty.
Example:
MyBuffer is Buffer

Declaring and initializing a Buffer variable

To declare and initialize a Buffer variable, use the following syntax:
<Variable name> is Buffer = [<Hex value 1>, <Hex value 2>, ..., <Hex value N>]
Details of syntax
<Variable name>:Name of the variable to declare.
Hexa valueHexadecimal value.

Example:
b is Buffer = [0x01, 0x02, 0x03]

Operations on a Buffer variable

Buffer variables can be handled in the same way as String variables.
To assign a Buffer variable, use one of the following syntaxes:
  • assigning a string to a Buffer variable:
    <Buffer variable name> = <My String>.
    For example:
    MyBuffer is Buffer
    MyBuffer = "WINDEV is great"
    // In ANSI, MyBuffer contains: WINDEV is great
    // In UNICODE, MyBuffer contains: 
    // W0i0n0D0e0v0 0i0s0 0gr0e0a0t0
  • assigning a byte of the Buffer variable:
    <Buffer variable name> [[<Byte index>]] = <Byte ASCII code>.
    For example:
    MyBuffer is Buffer
    MyBuffer[[1]] = 65 // MyBuffer contains "A"
Using functions:
  • Left, Right and Middle can be used on Buffer variables. For more details, see the help about these functions.
    WEBDEV - Browser code Not available.
  • Size is used to find out the real size of the data contained in the Buffer variable (in bytes).
Using operators:
The [[ ]] operator is used to access:
  • one byte of the Buffer variable. For example:
    MyBuffer is Buffer
    MyBuffer = "WINDEV is great"
    MyBuffer[[1]] = "W"
  • one part of the Buffer variable. For example:
    MyBuffer is Buffer
    MyBuffer = "WINDEV is great"
    Info(MyBuffer[[8 TO 15]])
WEBDEV - Browser code Not available.
Buffer comparison:
You can compare a buffer or a portion of a buffer to specific values.
For example, you can write:
IF MyBuffer = [1,2,3] THEN ...

IF MyBuffer[1 ON 2] = [1,2] THEN ...
WEBDEV - Browser code Not available.
'Buffer on' type: Syntax and advanced use

Declaring a Buffer On variable

<Variable name> is Buffer on <Buffer size>
OR
<Variable name 1>, <Variable name 2> are Buffers on <Size of buffers>
Details of syntax
<Variable name>:Name of the variable to declare.
<Buffer size>:Size of buffer in bytes.

Remarks:
  • The a and an keywords are optional: they provide better readability.
  • By default, the '0' character is assigned to a 'Buffer on' variable.
  • WEBDEV - Browser code The 'Buffer on' type is not available.
Examples:
MyBuffer is Buffer on 4
MyBuffer = "ABCDE" // MyBuffer contains "ABCD"
MyBuffer = "ZZ"    // MyBuffer contains "ZZCD"

Operations on 'Buffer on' variables (called fixed buffers)

Fixed buffers are handled like simple buffers. However, some differences must be taken into account.
At runtime, the actual size of the data contained in the Buffer variable is unknown:
  • The data written is truncated if it exceeds the size of the Buffer variable.
  • When writing data that is smaller than the size of the Buffer variable, the non-written section of the buffer keeps its previous value.
To handle this type of Buffer variable, it is recommended to always store the actual buffer size in an Integer variable.
Reminder: the Buffer type automatically manages its own size. When using a fixed buffer, we advise you to quickly copy its value into an automatic buffer.
// Use an API that returns the size of a buffer
bFixedBuffer is Buffer on 200
nSize is int
// Call the API
nSize = API(<API name>, <Parameters>, bFixedBuffer, 200)
// Copy the buffer
bBuffer is Buffer
bBuffer = Left(bFixedBuffer, nSize)
Minimum version required
  • Version 11
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 09/07/2023

Send a report | Local help