Aide:Static.txt
De Wiki AutoIt Français
Document original V3.3.6.1 :
###Keyword###
Static
###Experimental###
###Description###
Declare a static variable or create a static array.
###Syntax###
<b>Static</b> [Scope] $variable [ = initializer ]
<b>Static</b> [Scope] $array<b>[</b>subscript 1<b>]</b>...<b>[</b>subscript n<b>]</b> [ = initializer ]
###Parameters###
@@ParamTable@@
Scope
An optional modifier, <b>Local</b> or <b>Global</b> that indicates where the variable is visible.
$variable
The name of the static variable to declare.
initializer
The value that will be initially assigned to the variable. The initializer can be a function call of involve mathematical or string operations. This initializer is only evaluated the first time this variable declaration is encountered.
subscript
The number of elements to create for the array dimension, indexed 0 to n-1.
@@End@@
###Remarks###
The Static keyword can appear on the line before the optional scope specifier, or after. e.g. <b>Local Static</b> or <b>Static Local</b> are both acceptable.
If the scope modifier <b>Local</b> is used, then the static variable is visible and usable only in the function in which it is declared. If the scope modifier <b>Global</b> is used, then the static variable is visible and usable in all parts of the script; in this regard, a Global Static has very little difference from a Global variable. If the scope modifier is not used, then the static variable will be created in the local scope; in this way, Static is similar to Dim.
The difference between Local and Static is variable lifetime. Local variables are only stored while the function is called and are visible only within the function in which they are declared; when the function returns, all its local variables are released. Static variables are likewise visible only in the function in which they are declared, but they continue to exist, retaining their last value, after the function finishes execution. When looking for variables, the local scope is checked first and then the global scope second.
The Static keyword performs similar functions to the Global/Local/Dim keywords.
<ol><li>They all declare a variable before you use it.</li>
<li>They all can create an array.</li></ol>
<b>Note</b>: Static variables <i>must</i> be declared using the <b>Static</b> keyword prior to use, no matter how AutoItSetOption("MustDeclareVars") is set. Static variables can not be <b><a href="Dim.htm">Const</a></b>.
You can also declare multiple static variables on a single line:
<p class="code">Static $a, $b, $c</p>
And initialize the variables:
<p class="code">Static $a = 2, $b = 10, $c = 20</p>
When initializing a static variable, the initialization value is evaluated and assigned only the first time, when the variable is created. On all subsequent passes, the initializer is ignored.
See <a href="Dim.htm">Local</a> for more information about using arrays, which has all the same functionality as in Local, except for:
<ol><li>Reinitalizing a Static variable has no effect.</li>
<li>Changing the size of a Static array is treated like a ReDim.</li>
<li>You can not change a static variable to a local or global variable nor vice-versa.</li></ol>
If you want to resize an array, always use Static to do so, not Redim.
###Related###
<a href="Dim.htm">Local</a>, UBound, ReDim, <a href="../functions/AutoItSetOption.htm#MustDeclareVars">AutoItSetOption</a></b>
###Example###
@@IncludeExample@@
Document traduit V3.3.6.1 :
###Keyword###
Static
###Experimental###
###Description###
Déclare une variable statique ou crée un tableau statique.
###Syntax###
<b>Static</b> [Scope] $variable [ = initializer ]
<b>Static</b> [Scope] $array<b>[</b>subscript 1<b>]</b>...<b>[</b>subscript n<b>]</b> [ = initializer ]
###Parameters###
@@ParamTable@@
Scope
Un attribut optionnel, <b>Local</b> ou <b>Global</b> qui indique où la variable est visible.
$variable
Le nom de la variable statique à déclarer.
initializer
La valeur initiale assignée à la variable. La valeur initiale peut être un appel de fonction impliquant des mathématiques ou des opérations de chaînes. Cette valeur initiale n'est évaluée que lors de la première déclaration de celle-ci.
subscript
Le nombre d'éléments pour la dimension du tableau, index de 0 à n-1.
@@End@@
###Remarks###
Le mot-clé Static peut apparaître sur la ligne avant le spécificateur de portée facultatif, ou après. Ex: <b>Local Static</b> ou <b>Static Local</b> sont tous deux acceptables.
Si le modificateur de portée <b>Local</b> est utilisé, alors la variable statique n'est visible et utilisable que dans la fonction dans laquelle elle a été déclarée. Si le modificateur de portée <b>Global</b> est utilisé, alors la variable statique est visible et utilisable dans toutes les parties du script; à cet égard, une variable statique globale a très peut de différences par rapport à une variable globale. Si le modificateur de portée n'est pas utilisé, alors la variable statique sera créée dans la portée locale; de cette façon, Static est similaire à Dim.
La différence entre Local et Static est la durée de vie de la variable. Les variables locales ne sont stockées que pendant l'appel de la fonction où elles sont créées et ne sont visibles que par celle-ci; lorsque la fonction ce termine, toutes ses variables locales sont libérées. De même, les variables statiques sont visibles seulement dans la fonction dans laquelle on les déclare, mais elles continuent à exister, conservant leur dernière valeur, après l'exécution de la fonction. Lors de la recherche des variables, la portée locale est vérifiée en premier, puis la portée globale en second.
Le mot-clé Static exécute des fonctions semblables aux mots-clés Global/Local/Dim.
<ol><li>Ils déclarent tous une variable avant que vous ne l'utilisiez.</li>
<li>Ils peuvent tous créer un tableau.</li></ol>
<b>Note</b>: Les variables statiques <i>doivent</i> être déclarées en utilisant le mot-clé <b>Static</b> avant d'être utilisées, Peu importe comment AutoItSetOption("MustDeclareVars") est utilisé. Les variables statiques ne peuvent être <b><a href="Dim.htm">Const</a></b>.
Vous pouvez aussi déclarer de multiples variables statiques sur une seule ligne :
<p class="code">Static $a, $b, $c</p>
et initialiser les variables :
<p class="code">Static $a = 2, $b = 10, $c = 20</p>
Lors de l'initialisation d'une variable statique, la valeur d'initialisation est évaluée et assignée la première fois, lorsque la variable est créée. Sur toute passe ultérieure, l'initialisation est ignorée.
Voir <a href="Dim.htm">Local</a> pour plus d'informations sur l'utilisation des tableaux, qui ont la même fonctionnalité que dans Local, excepté pour :
<ol><li>La réinitialisation d'une variable Statique n'a aucun effet.</li>
<li>Le changement de la taille d'un tableau Statique est traité comme un ReDim.</li>
<li>Vous ne pouvez pas changer une variable statique en une variable locale ou globale, et vice versa.</li></ol>
Si vous voulez redimensionner un tableau, utilisez toujours Static pour le faire ainsi et non Redim.
###Related###
<a href="Dim.htm">Local</a>, <a href="../../html/functions/UBound.htm">UBound</a>, <a href="ReDim.htm">ReDim</a>, <a href="../functions/AutoItSetOption.htm#MustDeclareVars">AutoItSetOption</a>
###Example###
@@IncludeExample@@
Traducteur : Tlem