Basic Pascal Tutorial/Chapter 5/Records/ja
English · Français · Български · 中文(中国) · 日本語
5E - レコード型 (著者: Tao Yue, 状態: 原文のまま変更なし)
レコード型を使えば、関連したデータ項目をひとつの構造に収めておける。ある人について情報が欲しいとき、名前、年齢、都市、州、そして郵便番号が知りたいかもしれない。
レコード型を宣言するためには、以下のようにする。
TYPE
TypeName = record
??????????????????1 : ????????????1;
...
??????????????????n : ????????????n;
end;たとえば、
type
InfoType = record
name : string;
age : integer;
city, state : String;
zip : integer;
end;識別子 name, age, city, state と zip のそれぞれはフィールドとして参照される。次のようにして変数内のフィールドにアクセスできる。
???????????????.????????????????????????ピリオドで変数とフィールド名を分ける。
レコード型を扱うときにとても便利な命令文がある。ひとつのレコード型変数を長く用いるつもりで、変数名を繰り返し繰り返しタイプしたくないなら、変数名を除いて、フィールド識別子だけを用いることができる。以下のようにすればよい。
WITH ????????????????????? DO
BEGIN
...
END;たとえば、次のようになる。
with Info do
begin
age := 18;
zip := 90210;
end;| previous | contents | next |
From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 5/Records/ja", as it stood on 2022-08-20 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.