Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
So last night I had my last Pascal Class and Monday is the FINAL! I lost my book a month ago and finally got a new one 2 days ago and I am playing catchup.
By Monday I need to have read up on and understand
1. Arrays
2. Multi Dimensional Arrays
3. Records (which sounds like C Structs)

Each of these I get by there own for the most part. But combining them I get lost. Example, passing an ARRAY of RECORDS as a PARAMETER to a PROCEDURE

I was slowly working on some code and compiling as I went along and then hit a snag. I am getting a error in the PROCEDURE on this line Studentcard.idno := 3345; . I am trying to assign that integer value 3345 to the record being stored in that array. I must be over looking something obvious.

Code:
program procpass;

const
	numOfRecords = 30;


type
	numOfRecordes = 1..30;
	student = record
				name : char;
				major : integer;
				classtpe : integer;
				idno : integer;
			  end;
	oneRecord = array[numOfRecordes] of student;
	
var

	studentcard : oneRecord;

procedure inputdata(studentcard : oneRecord);
var
	i : integer;
	begin
		for i := 1 to 30 DO
			Studentcard.idno[i] := 3345;
	end;
begin
inputdata(studentcard);

end.

Any help is appreciated :)

-Lars
 
You didn't say what the error message said, which should have gave you a hint.

I have only got vague memories of pascal, but here goes...

You have an array of records, so to access a field in the record, you'd have to first access the record i.e. access an element of the array, then access its field.

Code:
studentcard[i].idno := 3345;

If its case insensitive, it wouldn't matter whether you use Studentcard or studentcard, but it doesn't look good if you change it every other time.
 
It is case insensitive and the error message I got was 'illegal Qualifier'

Thanks,

-Lars
 
It is case insensitive and the error message I got was 'illegal Qualifier'

Would be good to know on which line exactly the error is.

But your code won't work; you pass a record by value, so the global variable will not be modified. You probably want

Code:
procedure inputdata (var studentcard : oneRecord);
 
gnasher729 - Thanks, I found that out about 10 minutes ago looking through old notes. The var allows me to pass the address so I can get something out of that procedure.

I also fixed this
Studentcard.idno := 3345;

to this
Studentcard.idno := 3345;

and it works now.

Thanks for your help.

-Lars
 
So last night I had my last Pascal Class and Monday is the FINAL! I lost my book a month ago and finally got a new one 2 days ago and I am playing catchup.
By Monday I need to have read up on and understand
1. Arrays
2. Multi Dimensional Arrays
3. Records (which sounds like C Structs)

Each of these I get by there own for the most part. But combining them I get lost. Example, passing an ARRAY of RECORDS as a PARAMETER to a PROCEDURE

I was slowly working on some code and compiling as I went along and then hit a snag. I am getting a error in the PROCEDURE on this line Studentcard.idno := 3345; . I am trying to assign that integer value 3345 to the record being stored in that array. I must be over looking something obvious.

Code:
program procpass;

const
	numOfRecords = 30;


type
	numOfRecordes = 1..30;
	student = record
				name : char;
				major : integer;
				classtpe : integer;
				idno : integer;
			  end;
	oneRecord = array[numOfRecordes] of student;
	
var

	studentcard : oneRecord;

procedure inputdata(studentcard : oneRecord);
var
	i : integer;
	begin
		for i := 1 to 30 DO
			Studentcard.idno[i] := 3345;
	end;
begin
inputdata(studentcard);

end.

Any help is appreciated :)

-Lars

The problem is probably that idno isn't an array. It's a component of an element of an array. Try:

Code:
Studentcard[i].idno := 3345;

Or,

Code:
with Studentcard[i] do
   idno := 3345;
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.