### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: [SOLVED] Array definition by a set ?  (Read 173 times)

#### Nitorami

• Sr. Member
• Posts: 431
##### [SOLVED] Array definition by a set ?
« on: September 20, 2022, 11:59:17 am »
Hi there
I post this under beginners because I feel really stupid about the question - is it possible to limit array boundaries to a constant set somehow ?

Code: Pascal  [Select][+][-]
1. type TSelection = (a, b, c, d);
2.
3. const MyChoice = [b, c];
4.
5. type TCollector  = array [TSelection] of integer;  //OK
6. type TCollector2 = array [MyChoice] of integer;  //Error in Type definition.
7.
8. begin
9. end.

« Last Edit: September 20, 2022, 03:44:53 pm by Nitorami »

#### MarkMLl

• Hero Member
• Posts: 5596
##### Re: Array definition by a set ?
« Reply #1 on: September 20, 2022, 12:04:51 pm »
No, because a set can have gaps. Use an enumeration, or a subrange (of an enumeration, or of an integer type).

MarkMLl
« Last Edit: September 20, 2022, 12:22:48 pm by MarkMLl »
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

#### Nitorami

• Sr. Member
• Posts: 431
##### [CLOSED] Re: Array definition by a set ?
« Reply #2 on: September 20, 2022, 03:44:02 pm »
Yep, makes sense. I can in fact do
Code: Pascal  [Select][+][-]
1. type TCollector2 = array [b..c] of integer;
Thanks!

#### MarkMLl

• Hero Member
• Posts: 5596
##### Re: [SOLVED] Array definition by a set ?
« Reply #3 on: September 20, 2022, 03:50:24 pm »
And you have of course realised that the syntax is identical for a subrange of an enumeration and a subrange of an integer type :-)

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories