Set/fr: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | ## Introduction | |
| 2 | 2 | ||
| 3 | - | ||
| 4 | - | ||
| 5 | - | ||
| 3 | + | Un ensemble (set) code plusieurs valeurs d'une énumération vers un type Ordinal. | |
| 6 | 4 | ||
| 7 | - | ||
| 8 | - | ||
| 5 | + | Par exemple, prenons l'énumération: | |
| 9 | 6 | ``` | |
| 10 | - | ||
| 11 | - | ||
| 12 | - | ||
| 13 | - | ||
| 14 | - | ||
| 7 | + | TSpeed = (spVerySlow,spSlow,spAVerage,spFast,spVeryFast); | |
| 15 | 8 | ``` | |
| 16 | 9 | ||
| 17 | - | ||
| 10 | + | Et cet ensemble: | |
| 11 | + | ``` | |
| 12 | + | TPossibleSpeeds = set of TSpeed | |
| 13 | + | ``` | |
| 18 | 14 | ||
| 19 | - | ||
| 20 | - | ||
| 21 | - | ||
| 22 | - | ||
| 15 | + | TPossibleSpeeds peut être défini comme une constante entre crochets: | |
| 23 | 16 | ``` | |
| 17 | + | const | |
| 18 | + | RatherSlow = [spVerySlow,spSlow]; | |
| 19 | + | RatherFast = [spFast,spVeryFast]; | |
| 20 | + | ``` | |
| 24 | 21 | ||
| 25 | - | ||
| 22 | + | RatherSlow et RatherFast sont quelques ensembles de TSpeed. | |
| 26 | 23 | ||
| 27 | 24 | ## Manipulation des sets | |
| 28 | 25 | ||
| 29 | - | ||
| 30 | - | ||
| 31 | - | ||
| 32 | - | ||
| 33 | - | ||
| 34 | - | ||
| 35 | - | ||
| 36 | - | ||
| 37 | - | ||
| 38 | - | ||
| 26 | + | Habituellement, deux fonctions natives du compilateur sont employées pour manipuler un ensemble : **Include(UnEnsemble,UneValeur)** et **Exclude(UnEnsemble,UneValeur)**. | |
| 39 | 27 | ``` | |
| 40 | - | ||
| 41 | - | ||
| 42 | - | ||
| 43 | - | ||
| 44 | - | ||
| 45 | - | ||
| 46 | - | ||
| 47 | - | ||
| 48 | - | ||
| 49 | - | ||
| 50 | - | ||
| 51 | - | ||
| 28 | + | var | |
| 29 | + | SomeSpeeds = TPossibleSpeeds; | |
| 30 | + | begin | |
| 31 | + | SomeSpeeds := []; | |
| 32 | + | Include(SomeSpeeds,spVerySlow); | |
| 33 | + | Include(SomeSpeeds,spVeryFast); | |
| 34 | + | end; | |
| 52 | 35 | ``` | |
| 53 | 36 | ||
| 54 | - | ||
| 37 | + | 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. | |
| 38 | + | ``` | |
| 39 | + | procedure TSomething.DoSomething(Sender: TFarObject); | |
| 40 | + | var | |
| 41 | + | LocalCopy = TPossibleSpeeds; | |
| 42 | + | begin | |
| 43 | + | LocalCopy := Sender.PossibleSpeeds; // getter to local | |
| 44 | + | Include(LocalCopy,spVerySlow); | |
| 45 | + | Sender.PossibleSpeeds := LocalCopy; // local to setter. | |
| 46 | + | end; | |
| 47 | + | ``` | |
| 55 | 48 | ||
| 56 | - | ||
| 57 | - | ||
| 58 | - | ||
| 59 | - | ||
| 60 | - | ||
| 61 | - | ||
| 62 | - | ||
| 63 | - | ||
| 49 | + | 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: | |
| 64 | 50 | ``` | |
| 51 | + | var | |
| 52 | + | CanBeSlow: Boolean; | |
| 53 | + | const | |
| 54 | + | SomeSpeeds = [Low(TSpeed)..High(TSpeed)]; | |
| 55 | + | begin | |
| 56 | + | CanBeSlow := (spVerySlow in SomeSpeeds) or (spSlow in SomeSpeeds); | |
| 57 | + | end; | |
| 58 | + | ``` | |
| 65 | 59 | ||
| 66 | - | ||
| 60 | + | Les ensembles supportent aussi des opération ensemblistes sous la forme d'opérateurs décrits dans [Set operators](<http://www.freepascal.org/docs-html/ref/refsu45.html#x139-14900012.8.5%7C>) | |
| 67 | 61 | ||
| 62 | + | Types de données | |
| 63 | + | --- | |
| 64 | + | Types de données simples | [[Boolean/fr|Boolean]] | [[Byte/fr|Byte]] |[[Cardinal/fr|Cardinal]] | [[Char/fr|Char]] | [[Currency/fr|Currency]] | [[Extended/fr|Extended]] | [[Int64/fr|Int64]] | [[Integer/fr|Integer]] | [[Longint/fr|Longint]] | [[Pointer/fr|Pointer]] | [[Real/fr|Real]] | [[Shortint/fr|Shortint]] | [[Smallint/fr|Smallint]] | [[Word/fr|Word]] | |
| 65 | + | Types de données complexes | [[Array/fr|Array]] | [[Class/fr|Class]] | [[Record/fr|Record]] | Set | [[String/fr|String]] | [[Shortstring/fr|ShortString]] | |
| 66 | + | ||
| 68 | 67 | --- | |
| 69 | - | ||
| 68 | + | *From the Free Pascal wiki, page "Set/fr", as the Internet Archive kept it on 2025-03-23, last changed on 2020-02-27. 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).* |
