1
votes

I'm having problems creating an array of records with an array of records inside.

type
    SubjectsRec = array of record
        subjectName : String;
        grade : String;
        effort : Integer;
    end;
    TFileRec = array of record
        examinee : String;
        theirSubjects: array of SubjectsRec;
    end;

var
    tfRec: TFileRec;
    i: Integer;
begin
    setLength(tfRec,10);
    for i:= 0 to 9 do
    begin
       setLength(tfRec[i].theirSubjects,10);
    end;

After this I was hoping to assign values by doing this:

tfRec[0].theirSubjects[0].subjectName:= "Mathematics";

However, I get:

Error: Illegal qualifier

when trying to compile.

2
Please mention what compiler you use. - Marco van de Voort
@Wes if my answer helped you, would you mind to accept it as the correct one clicking on the big "V" just in the left of the answer? :) - brandizzi

2 Answers

2
votes

You declared SubjectsRec as an array of records, and then declared the TheirSubjects field as an array of SubjectRecs - that is, TheirSubjects is an array of arrays of records.

There are two solutions:

Declare TheirSubjects as having the type SubjectsRec, instead of array of subjectsRec:

TFileRec = array of record
  examinee : string;
  theirSubjects: SubjectsRec;
end;

or declare SubjectsRec as a record, not as an array. This is my favorite one:

SubjectsRec = record
  subjectName : String;
  grade : String;
  effort : Integer;
end;
TFileRec = array of record
  examinee : string;
  theirSubjects: array of SubjectsRec;
end;

Also, strings in Pascal are delimited by single quotes, so you should replace "Mathematics" by 'Mathematics'.

1
votes

I think you should change this:

tfRec[0].theirSubjects[0].subjectName:= "Mathematics";

to

tfRec[0].theirSubjects[0].subjectName:= 'Mathematics';