Sets
Select a set type
A set holds zero or more members from one ordinal element type. Unlike an array, a set has no ordering, duplicates or numeric indexes.
| Type | Element domain | Primary use | Important boundary |
|---|---|---|---|
TComponentState | Eleven component lifecycle/design flags | Inspect inherited component state | Read-only snapshot controlled by the component framework. |
TIdMessageFlagsSet | TIdMessageFlags | IMAP/message state | Local replacement is not an atomic mailbox update. |
TLocateOptions | TLocateOption | Dataset Locate matching options | Provider behavior varies and success moves the cursor. |
TvxChars | 8-bit Char values | Allowed/removed character membership | Cannot represent arbitrary Unicode characters. |
TvxSeparators | 8-bit Char values | Token separator membership | Each member is an independent one-character separator. |
Set syntax and operators
Flags := [mfSeen, mfAnswered];
if mfSeen in Flags then
Exclude(Flags, mfSeen);
Flags := Flags + [mfFlagged]; // union
Flags := Flags - [mfDeleted]; // difference
Flags := Flags * [mfSeen, mfFlagged]; // intersection
The modified PascalScript compiler/runtime supports:
[]for the empty set and[A, B]for a set constructor;Element in Valuefor membership;Include(Value, Element)andExclude(Value, Element)for in-place mutation;+,-and*for union, difference and intersection;=,<>,<=and>=for equality and subset/superset comparisons.
Both operands of a set operation must be the same set type. Set assignment copies the fixed bit field; it does not share backing storage like a dynamic array. Use named members rather than persisting the internal bit pattern, because ordinal changes at the element-type boundary change that representation.
Boundary rules
- A set member's ordinal must fit the type's registered range. The current public types use no more than 256 possible ordinals.
constset parameters prevent reassignment through that parameter;varparameters and writable properties can replace the caller's complete set.- Test flags individually when semantics are independent. Equality with a one-member constructor rejects any additional flags.
- An empty set means no selected flags/options; it is not Null and carries no unknown state by itself.
- Character sets are limited to the 8-bit public
Chardomain even though the current scriptStringis Unicode.
External references
- Embarcadero structured types - Delphi set declarations, constructors and membership.
- Free Pascal set types - compatible ordinal-domain and 256-member limits.
- Free Pascal set operators - compatible membership, mutation and combination operators.