menu prev next

with RECORDS
The with statement, in association with records, allows a quick and easy way of accessing each of the records members without using the dot notation.

Consider the following program example, where the variable student record is initialised. Note how the name of the record is associated with each of the initialised parts. Then look at the code that follows, and note the difference being the absence of the record name.


	program withRecords( output );
	
	type	Gender = (Male, Female);
		Person = Record
			Age : Integer;
			Sex : Gender
		end;

	var Student : Person;

	begin
		Student.Age := 23;
		Student.Sex := Male;

		with Student do begin
			Age := 19;
			Sex := Female
		end;

		with Student do begin
			Writeln( 'Age := ', Age );
			case Sex of
				Male   : Writeln( 'Sex := Male' );
				Female : Writeln( 'Sex := Female' )
			end
		end
	end.


Copyright B Brown/P Henry/CIT, 1988-1997. All rights reserved.
menu prev next

1