Set/fr: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Set/fr
| Old | New | Line | |
|---|---|---|---|
| 1 | + | ## Introduction | |
| 2 | + | ||
| 3 | + | Un ensemble (set) code plusieurs valeurs d'une énumération vers un type Ordinal. | |
| 4 | + | ||
| 5 | + | Par exemple, prenons l'énumération: | |
| 6 | + | ||
| 7 | + | ``` pascal | |
| 8 | + | TSpeed = (spVerySlow,spSlow,spAVerage,spFast,spVeryFast); | |
| 9 | + | ``` | |
| 10 | + | ||
| 11 | + | Et cet ensemble: | |
| 12 | + | ||
| 13 | + | ``` pascal | |
| 14 | + | TPossibleSpeeds = set of TSpeed | |
| 15 | + | ``` | |
| 16 | + | ||
| 17 | + | TPossibleSpeeds peut être défini comme une constante entre crochets: | |
| 18 | + | ||
| 19 | + | ``` pascal | |
| 20 | + | const | |
| 21 | + | RatherSlow = [spVerySlow,spSlow]; | |
| 22 | + | RatherFast = [spFast,spVeryFast]; | |
| 23 | + | ``` | |
| 24 | + | ||
| 25 | + | RatherSlow et RatherFast sont quelques ensembles de TSpeed. | |
| 26 | + | ||
| 27 | + | ## Manipulation des sets | |
| 28 | + | ||
| 29 | + | Habituellement, deux fonctions natives du compilateur sont employées pour manipuler un ensemble : **Include(UnEnsemble,UneValeur)** et **Exclude(UnEnsemble,UneValeur)**. | |
| 30 | + | ||
| 31 | + | ``` pascal | |
| 32 | + | var | |
| 33 | + | SomeSpeeds = TPossibleSpeeds; | |
| 34 | + | begin | |
| 35 | + | SomeSpeeds := []; | |
| 36 | + | Include(SomeSpeeds,spVerySlow); | |
| 37 | + | Include(SomeSpeeds,spVeryFast); | |
| 38 | + | end; | |
| 39 | + | ``` | |
| 40 | + | ||
| 41 | + | Les ensembles ne peuvent être directement manipulés s'ils sont des propriétés publiées d'une classe. Vous devez normalement alors faire une copie locale, la modifier et passer cette valeur au setter. | |
| 42 | + | ||
| 43 | + | ``` pascal | |
| 44 | + | procedure TSomething.DoSomething(Sender: TFarObject); | |
| 45 | + | var | |
| 46 | + | LocalCopy = TPossibleSpeeds; | |
| 47 | + | begin | |
| 48 | + | LocalCopy := Sender.PossibleSpeeds; // getter to local | |
| 49 | + | Include(LocalCopy,spVerySlow); | |
| 50 | + | Sender.PossibleSpeeds := LocalCopy; // local to setter. | |
| 51 | + | end; | |
| 52 | + | ``` | |
| 53 | + | ||
| 54 | + | Le mot-clé **in** est aussi utilisé pour vérifier si une valeur est dans un ensemble. Généralement, c'est de la forme: | |
| 55 | + | ||
| 56 | + | ``` pascal | |
| 57 | + | var | |
| 58 | + | CanBeSlow: Boolean; | |
| 59 | + | const | |
| 60 | + | SomeSpeeds = [Low(TSpeed)..High(TSpeed)]; | |
| 61 | + | begin | |
| 62 | + | CanBeSlow := (spVerySlow in SomeSpeeds) or (spSlow in SomeSpeeds); | |
| 63 | + | end; | |
| 64 | + | ``` | |
| 65 | + | ||
| 66 | + | Les ensembles supportent aussi des opération ensemblistes sous la forme d'opérateurs décrits dans \[<http://www.freepascal.org/docs-html/ref/refsu45.html#x139-14900012.8.5>\| Set operators\] | |
| 67 | + | ||
| 68 | + | --- | |
| 69 | + | *From the Free Pascal wiki, page "Set/fr", as it stood on 2020-02-26 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
