PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • Overview
  • Why should I use a 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/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
The "Buffer" type (Type of variable)
Overview
The buffer type corresponds to a binary memory area.
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 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.
Versions 15 and later
Java This type of variable is now available for Java applications.
New in version 15
Java This type of variable is now available for Java applications.
Java This type of variable is now available for Java applications.
Versions 16 and later
Universal Windows 10 App This type of variable is now available for Windows Phone 7 applications.
New in version 16
Universal Windows 10 App This type of variable is now available for Windows Phone 7 applications.
Universal Windows 10 App This type of variable is now available for Windows Phone 7 applications.
Versions 17 and later
iPhone/iPad This type of variable is now available for iPhone/iPad applications.
New in version 17
iPhone/iPad This type of variable is now available for iPhone/iPad applications.
iPhone/iPad This type of variable is now available for iPhone/iPad applications.
Versions 18 and later
Universal Windows 10 App This type of variable is now available in Windows Store apps mode.
Android Widget This type of variable is now available in Android Widget mode.
Android This type of variable is now available for Android applications.
New in version 18
Universal Windows 10 App This type of variable is now available in Windows Store apps mode.
Android Widget This type of variable is now available in Android Widget mode.
Android This type of variable is now available for Android applications.
Universal Windows 10 App This type of variable is now available in Windows Store apps mode.
Android Widget This type of variable is now available in Android Widget mode.
Android This type of variable is now available for Android applications.
Versions 21 and later
Universal Windows 10 App This type of variable is now available in Universal Windows 10 App mode.
Apple Watch This type of variable is now available in Apple Watch mode.
New in version 21
Universal Windows 10 App This type of variable is now available in Universal Windows 10 App mode.
Apple Watch This type of variable is now available in Apple Watch mode.
Universal Windows 10 App This type of variable is now available in Universal Windows 10 App mode.
Apple Watch This type of variable is now available in Apple Watch mode.
Versions 22 and later
WINDEV MobileAndroidAndroid Widget This type of variable is now optimized to handle bytes.
New in version 22
WINDEV MobileAndroidAndroid Widget This type of variable is now optimized to handle bytes.
WINDEV MobileAndroidAndroid Widget This type of variable is now optimized to handle bytes.
Why should I use a buffer type?
In WINDEV, the following code can be used to handle binary bytes:
S is string = Charact(1) + Charact(0)
The corresponding memory area 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
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.
Remarks:
  • 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 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:
    <Name of Buffer variable> = <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:
    <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 Buffer variables. 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 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]])
AndroidAndroid Widget The [[ ]] operator is not available.
Versions 22 and later
AndroidAndroid Widget The [[ ]] operator is now available.
New in version 22
AndroidAndroid Widget The [[ ]] operator is now available.
AndroidAndroid Widget The [[ ]] operator is now available.
'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.
Remarks:
  • The a and an keywords are optional: they provide better readability.
  • By default, a Buffer on variable is filled with '0'.
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