PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • Overview
  • Why should I use a buffer type?
  • The Buffer type: Syntax and use
  • Declaring a Buffer variable
  • Declaring and initializing a Buffer variable
  • Operations on the buffers
  • The Buffer On type: Syntax and advanced use
  • Declaring a Buffer On variable
  • Handling the fixed buffers
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
The "Buffer" type (Type of variable)
Overview
The buffer type corresponds to a binary memory zone.
Via this type, a code that handles the binary format can be shared between a standard WINDEV application and a WINDEV Mobile application.
In standard WINDEV, a character 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, we recommend that you use a buffer variable.
The buffer type manages no specific end marker and it allows you to store binary zeros.
Two types of variables are available:
  • Buffer: This type allows you to manage a memory zone with a dynamic size: it is automatically adapted to the buffer content.
  • Buffer on: This type is used to handle a memory zone 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.
Versions 15 and later
Java This type of variable is now available for the Java applications.
New in version 15
Java This type of variable is now available for the Java applications.
Java This type of variable is now available for the Java applications.
Versions 16 and later
Universal Windows 10 App This type of variable is now available for the Windows Phone applications.
New in version 16
Universal Windows 10 App This type of variable is now available for the Windows Phone applications.
Universal Windows 10 App This type of variable is now available for the Windows Phone applications.
Versions 18 and later
Universal Windows 10 App This type of variable is now available in Windows Store apps mode.
New in version 18
Universal Windows 10 App This type of variable is now available in Windows Store apps mode.
Universal Windows 10 App This type of variable is now available in Windows Store apps mode.
Versions 21 and later
Universal Windows 10 App This type of variable is now available in Universal Windows 10 App mode.
New in version 21
Universal Windows 10 App This type of variable is now available in Universal Windows 10 App mode.
Universal Windows 10 App This type of variable is now available in Universal Windows 10 App mode.
Why should I use a buffer type?
In WINDEV, the following code can be used to handle the binary bytes:
S is string = Charact(1) + Charact(0)
The corresponding memory zone is:
01
This same code run in ANSI (WINDEV standard) and Unicode (WINDEV Mobile) does not have the same behavior.
To have the same code in ANSI and in UNICODE, the string must be replaced by a buffer. The code becomes:
S is Buffer
S[[1]] = 1
S[[2]] = 0
The Buffer type: Syntax and use

Declaring a Buffer variable

  • <Variable name> is Buffer
OR
  • <Name of variable 1>, <Name of variable 2> are Buffers
Details of syntax
<Variable name>:Name of variable to declare.
Notes:
  • The a and an keywords are optional: they provide better readability.
  • By default, a buffer variable is empty.
Example:
MyBuffer is Buffer
Versions 19 and later

Declaring and initializing a Buffer variable

To declare and initialize a Buffer variable, use the following syntax:
<Variable name> is Buffer = [<Hexa value 1>, <Hexa value 2>, ..., <Hexa value N>]
Details of syntax
<Variable name>:Name of variable to declare.
Hexa valueHexadecimal value
Example:
b is Buffer = [0x01, 0x02, 0x03]
New in version 19

Declaring and initializing a Buffer variable

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

Declaring and initializing a Buffer variable

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

Operations on the buffers

The buffers can be handled like the character strings.
To assign a buffer, use one of the following syntaxes:
  • assigning a buffer string:
    <Name of Buffer variable> = <My String>.
    For example:
    MyBuffer is Buffer
    MyBuffer = "WINDEV is great"
    // In ANSI, the buffer contains: WINDEV is fantastic
    // In UNICODE, the buffer contains:
    // W0i0n0D0e0v0 0e0s0t0 0f0o0r0m0i0d0a0b0l0e0
  • assigning a buffer byte:
    <Name of Buffer variable> [[<Byte subscript>]] = <ASCII code of byte>.
    For example:
    MyBuffer is Buffer
    MyBuffer[[1]] = 65 // MyBuffer contains "A"
Using functions:
  • Left, Right and Middle can be used on the buffers. See the help about these functions for more details.
  • Size is used to find out the real size of the data contained in the buffer (in bytes).
Using operators:
The [[ ]] operator is used to access:
  • a byte of the buffer. For example:
    MyBuffer is Buffer
    MyBuffer = "WINDEV is great"
    MyBuffer[[1]] = "W"
  • a section of the buffer. For example:
    MyBuffer is Buffer
    MyBuffer = "WINDEV is great"
    Info(MyBuffer[[8 TO 15]])
The Buffer On type: Syntax and advanced use

Declaring a Buffer On variable

<Variable name> is Buffer On <Buffer size>
OR
<Name of variable 1>, <Name of variable 2> are Buffers On <Size of buffers>
Details of syntax
<Variable name>:Name of variable to declare.
<Buffer size>: Size of buffer in bytes
Notes:
  • The a and an keywords are optional: they provide better readability.
  • By default, a buffer on variable is filled with the 0 character.
Examples:
MyBuffer is Buffer on 4
MyBuffer = "ABCDE" // MyBuffer contains "ABCD"
MyBuffer = "ZZ"    // MyBuffer contains "ZZCD"

Handling the fixed buffers

The fixed buffers are handled like the simple buffers. However, some differences must be taken into account.
At run time, the real size of the data found in the buffer is not known:
  • When writing data that is longer than the buffer size, the data is truncated to the size of the buffer.
  • When writing data that is smaller than the buffer size, the section of the buffer not affected by the write operation keeps its previous value.
To handle this type of buffer, we recommend that you store the actual size of the buffer 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