[Pascal – TUT] Posts 9: Type of record – Record

1. Declare:

the. Declaring indirect
Syntax:

Type
	<Tên kiểu> = RECORD
		<Tên trường 1> :<Kiểu trường>
		<Tên trường 2>:<Kiểu trường>
		...
	END;

Example:

Type
	date=RECORD
		ngay,thang:byte;
		nam:word;
	End;

	HOCSINH = RECORD
		MaSV:string[15];
		Hoten:string[30];
		Ngaysinh:date;
		Diachi: String;
	End;

Noted: Without testing earlier date can be described directly as follows:

Type
	HOCSINH = RECORD
		MaSV:string[15];
		Hoten:string[30];
		Ngaysinh:record {sử dụng khai báo trực tiếp}
			ngay:1..31;
			thang:1..12;
			nam:word;
		End;
		Diachi: String;
	End;

Var
	HSA,HSB: HOCSINH;
	Lop12A: Array[1..50] of HOCSINH;

b. Declaring directly
Syntax:

<pre>var
	<tên kiểu>: RECORD
		<Tên trường 1> :<Kiểu trường>
		<Tên trường 2>:<Kiểu trường>
		...
	END;

2. Access a variable record

To retrieve the record variable to have access to all of the variables with the following syntax:

<Tên biến record>.<tên trường>

Attention:
– The same type of record variables can be assigned to each other while processing all the information from this record will be assigned to variables other record.
For example, we assign: HSA:= HSB instead must perform assigned to each of the variables as
HSA.hoten:= HSB.hoten;
HSA.ngaysinh:= HSB.ngaysinh;

– You can use comparisons =, <> give 2 variable record but can not be used for comparison <,<=,>,>=.
For example, we can compare:
if HSA=HSB then writeln('Provide a student');
HOAc IF HSA.hoten = HSB.hoten then writeln('The ten pupils');
But not comparable:
if HSA>HSB then writeln(‘HS A lon hon HS B’);
– Do not use the procedure read, readln, write, writeln for a variable record
For example, can not be used:
writeln(HSA);
– Do not use all arithmetic and logic with variable record.

pascal

3. With statement

As seen on the access to a field variable Record by name and dots, complicates program, settle down somewhat this complexity, Pascal made the statement With … do
Syntax:

WITH <biến kiểu record> Do <câu lệnh>;

Attention:
We can nest statements together with due to visit schools in the string of record.
For example, the high school student and Ngaysinh are variable but ngaysinh is a school record of hocsinh we can write the following:

WITH HOCSINH DO
	WITH ngaysinh DO
		<lệnh>;

or

WITH HOCSINH, ngaysinh DO
	<lệnh>;

Original article : vietsource.net

Do sequencing post should have little confused Posts 10: Files in pascal - File Type was written earlier, you see here nhé.