ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage syntax / WLanguage types
  • Why use the Buffer type?
  • Assigning a Buffer variable
  • Using functions
  • Operators
  • Buffer comparison
  • Manipulating 'Buffer of' variables (called fixed buffers)
  • Notes
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Buffer (Type de variable)
In french: Buffer
The Buffer type corresponds to a binary memory area.
This type allows for full portability of code manipulating binary data between a standard WINDEV application 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 string variable contains binary data, this data may be corrupted (due to conversion errors, for example). To manipulate 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 is used to manipulate a memory zone whose size is dynamic: it automatically adapts to the buffer content.
  • Buffer on: This type is used to manipulate a memory zone whose size (in bytes) is set at compile time.. This is an advanced type used to perform specific operations in memory and use some Windows APIs.
Note: Buffer variables are base64 encoded in JSON and XML.
The Buffer type supports null values. For more details, see Allowing nullable types.
WEBDEV - Browser code In browser code, the Buffer type is limited: in particular, it is available to use functions BufferToHexa and HexaToBuffer, function Length 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 = Caract(1) + Caract(0)
The corresponding memory area is:
01

The same code executed in ANSI and Unicode does not behave in the same way.
To have an identical code in ANSI and Unicode, it is necessary to replace the string with a buffer.. The code becomes:
S is Buffer
S[[1]] = 1
S[[2]] = 0
Syntax

Declaring a Buffer variable Hide the details

<Variable name> is Buffer

<Variable name 1>, <Variable name  2> are Buffers
<Variable name>:
Name of the variable to declare. By default, a Buffer variable is empty.

Declaring and initializing a Buffer variable Hide the details

<Variable name> is Buffer = [<Hex value 1>, <Hex value 2>, ..., <Hex value N>]
<Variable name>:
Name of the variable to declare.
<Hexa value>:
Hexadecimal value.
Example:
b is Buffer = [0x01, 0x02, 0x03]

Declaring a 'Buffer of' variable Hide the details

<Variable name> is Buffer of <Buffer size>

<Variable name 1>, <Variable name 2> are Buffers of <Size of buffers>
<Variable name>:
Name of the variable to declare. By default, a Buffer variable is empty.
<Buffer size>:
Buffer size expressed in bytes.
By default, the '0' character is assigned to a 'Buffer of' variable.
WEBDEV - Browser code The 'Buffer of' type is not available.
Examples:
MonBuffer is Buffer on 4
MonBuffer = "ABCDE" // MonBuffer contient "ABCD"
MonBuffer = "ZZ"    // MonBuffer contient "ZZCD"
Remarks

Assigning a Buffer variable

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:
    MonBuffer is Buffer
    MonBuffer = "WINDEV est formidable"
    // En ANSI, la variable MonBuffer contient: WINDEV est formidable
    // En UNICODE, la variable MonBuffer contient: 
    // W0i0n0D0e0v0 0e0s0t0 0f0o0r0m0i0d0a0b0l0e0
  • assigning a byte of the Buffer variable:
    <Buffer variable name> [[<Byte index>]] = <Byte ASCII code>.
    For example:
    MonBuffer is Buffer
    MonBuffer[[1]] = 65 // MonBuffer contient "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.
  • Length is used to find out the real size of the data contained in the Buffer variable (in bytes).

Operators

The [[ ]] operator is used to access:
  • one byte of the Buffer variable. For example:
    MonBuffer is Buffer
    MonBuffer = "WINDEV est formidable"
    MonBuffer[[1]] = "W"
  • one part of the Buffer variable. For example:
    MonBuffer is Buffer
    MonBuffer = "WINDEV est formidable"
    Info(MonBuffer[[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:
SI MonBuffer = [1,2,3] ALORS ...

SI MonBuffer[1 SUR 2] = [1,2] ALORS ...
WEBDEV - Browser code Not available.

Manipulating 'Buffer of' variables (called fixed buffers)

Fixed buffers are manipulated in the same way as standard buffers. However, some differences should be noted.
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.
Remember: the Buffer type automatically manages its size. When using a fixed buffer, we advise you to quickly copy its value to an automatic buffer.
// Utilisation d'une API retournant la taille d'un buffer
bBufferFixe est un Buffer sur 200
nTaille est un entier
// Appel de l'API
nTaille = API(<Nom API>, <Paramètres>, bBufferFixe,200)
// Copie du buffer
bBuffer est un Buffer
bBuffer = Gauche(bBufferFixe, nTaille)
Notes
A "Buffer" variable is limited to 2 GB.. Indirectly, functions manipulating buffers are affected by this limit.
Minimum version required
  • Version 11
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 09/24/2024

Send a report | Local help