====== Array ====== ===== Array Static ===== TArrayOfString = array[0..19] of string; // Tableau de 20 strings TFormsProps = (fpWidth,fpHeight); // Type énuméré TFormsPropNames = array[fpWidth..fpHeight] of string; // Tableau ayant comme index un type énuméré ==== Plusieurs dimensions ==== Ce dessous la variable ''vArrayOfWord'' contient un tableau a deux dimensions de 0..19 et 0..2\\ (comme un tableau de 19 sur 2 cases) vArrayOfWord : array[0..19][0..2] of word; ===== Array Dynamic ===== ==== Déclaration ==== var // 1 dimension vArr: array of Integer; // 2 dimensions vArr2D : array of array of integer; ==== Allocation ==== // 1 dimension SetLength(vArr, 10); Initialize(vArr, 10); //Met a zéro : Optionnel // 2 dimensions SetLength(vArr2D, 10, 10); ==== Libération ==== // Soit SetLength(vArr, 0); // Soit Finalize(vArr); // Soit vArr := nil; J'ai testé et les trois ont le même effet, ils libèrent la même quantité de mémoire. Il est dit [[https://wiki.freepascal.org/Dynamic_array/fr|ICI]]:\\ En affectant ''nil'' à une variable tableau dynamique, la mémoire désignée par le pointeur est automatiquement libérée. C'est équivalent à ''SetLength(MyVariable, 0)''. Cela peut avoir un effet de bord, si la valeur du pointeur n'est pas valide pour différente raisons (i.e., cela a été lu depuis le disque où cela a été enregistré lors d'une précédente exécution). Pour éviter un tel pointeur invalide, vous devez utiliser ''FillChar(MyVariable,sizeof(MyVariable), #0)''. ===== Array en Const ===== DayNameShort: array [DayStart .. DayEnd] of string= ( 'Sun','Mon','Tue','Wed','Thu', 'Fri','Sat' ) ; ===== Comparaisons ===== * [[https://www.arbinada.com/en/node/1411|Comparaison Array / Dynamic Array / TList]] ====== Voir aussi ====== * [[prog:lazarus:classes:tlist]] ====== Sources & Ressources ====== * Source : [[https://wiki.freepascal.org/Dynamic_array/fr]] * Exemple de tableau dynamique multidimensionnel : [[https://wiki.freepascal.org/Example:_Multidimensional_dynamic_array/fr]] * [[https://hdd34.developpez.com/articles/artdynarr/]] * [[https://www.arbinada.com/en/node/1411|Comparaison Array / Dynamic Array / TList]]