|
|
|
|
|
- Why use the Buffer type?
- Assigning a Buffer variable
- Using functions
- Operators
- Buffer comparison
- Manipulating 'Buffer of' variables (called fixed buffers)
- Notes
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. 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:
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.
Examples: MonBuffer is Buffer on 4
MonBuffer = "ABCDE"
MonBuffer = "ZZ"
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"
- assigning a byte of the Buffer variable:
<Buffer variable name> [[<Byte index>]] = <Byte ASCII code>. For example:
MonBuffer is Buffer
MonBuffer[[1]] = 65
Using functions - Left, Right and Middle can be used on Buffer variables. For more details, see the help about these functions.
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]])
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 ... 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) A "Buffer" variable is limited to 2 GB.. Indirectly, functions manipulating buffers are affected by this limit.
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|