4 ms·
type TPerson = record name: string; age: integer; end; TThrteenPersons = array[10..22] of TPerson; procedure Check(const aPerson: TPe
by FpUser 6y ago
type
TPerson = record
name: string;
age: integer;
end;
TThrteenPersons = array[10..22] of TPerson;
procedure Check(const aPerson: TPerson);
var
vPerson: TThrteenPersons;
begin
vPerson[11] := aPerson; // this is ok
vPerson[1] := aPerson; // this one gives compile error
end;
alternatively if runtime range checking is on then vPerson[i] = aPerson will raise the exception if i is out of range
- Jtsummers 6y agoRight. I know it works with numeric indexes in Pascal. My point was that (using my previous example) in Ada it works with any discrete type, in that case characters (which are not numbers in disguise in Ada) so I can do this: Histogram : Character_Histogram; ... Histogram['A'] := Histogram['A'] + 1; (Ok, a bit more work because I didn't initialize the histogram to 0.)
- Lucretia9 6y agoSquare brackets are coming, so you'd have to use ('A')
- Jtsummers 6y agoHah, I've been in Go lately so my brain defaulted to the wrong thing in that example.
- FpUser 6y agoPascal (well Delphi/FreePascal incarnation) also works with chars and enums. This modern pascal is very feature rich and has plenty of fancy bells and whistles.
- kwhitefoot 6y agoIt works with any ordinal type in Pascal, including characters, booleans and enums.