Difference between revisions of "Basic Pascal Tutorial/Chapter 5/Records/ja"

From Free Pascal wiki
Jump to navigationJump to search
(Created page with "{{Records/ja}} 5E - レコード (著者: Tao Yue, 状態: 原文のまま変更なし) A record allows you to keep related data items in one structure. If you want informat...")
 
Line 1: Line 1:
 
{{Records/ja}}
 
{{Records/ja}}
  
5E - レコード (著者: Tao Yue, 状態: 原文のまま変更なし)
+
5E - レコード型 (著者: Tao Yue, 状態: 原文のまま変更なし)
  
A record allows you to keep related data items in one structure. If you want information about a person, you may want to know name, age, city, state, and zip.
+
レコード型を使えば、関連したデータ項目をひとつの構造に収めておける。ある人について情報が欲しいとき、名前、年齢、都市、州、そして郵便番号が知りたいかもしれない。
  
To declare a record, you'd use:
+
レコード型を宣言するためには、以下のようにする。
 
<syntaxhighlight>
 
<syntaxhighlight>
 
TYPE
 
TYPE
 
   TypeName = record
 
   TypeName = record
     identifierlist1 : datatype1;
+
     識別子リスト1 : データ型1;
 
     ...
 
     ...
     identifierlistn : datatypen;
+
     識別子リストn : データ型n;
 
   end;
 
   end;
 
</syntaxhighlight>
 
</syntaxhighlight>
  
For example:
+
たとえば、
 
<syntaxhighlight>
 
<syntaxhighlight>
 
type
 
type
 
   InfoType = record
 
   InfoType = record
     Name : string;
+
     name : string;
     Age : integer;
+
     age : integer;
     City, State : String;
+
     city, state : String;
     Zip : integer;
+
     zip : integer;
 
   end;
 
   end;
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Each of the identifiers <tt>Name, Age, City, State</tt>, and <tt>Zip</tt> are referred to as fields. You access a field within a variable by:
+
識別子 <tt>name, age, city, state</tt> <tt>zip</tt> のそれぞれはフィールドとして参照される。次のようにして変数内のフィールドにアクセスできる。
 
<syntaxhighlight>
 
<syntaxhighlight>
  VariableIdentifier.FieldIdentifier
+
  変数識別子.フィールド識別子
 
</syntaxhighlight>
 
</syntaxhighlight>
  
A period separates the variable and the field name.
+
ピリオドで変数とフィールド名を分ける。
  
There's a very useful statement for dealing with records. If you are going to be using one record variable for a long time and don't feel like typing the variable name over and over, you can strip off the variable name and use only field identifiers. You do this by:
+
レコード型を扱うときにとても便利な命令文がある。ひとつのレコード型変数を長く用いるつもりで、変数名を繰り返し繰り返しタイプしたくないなら、変数名を除いて、フィールド識別子だけを用いることができる。以下のようにすればよい。
 
<syntaxhighlight>
 
<syntaxhighlight>
WITH RecordVariable DO
+
WITH レコード型変数 DO
 
BEGIN
 
BEGIN
 
   ...
 
   ...
Line 41: Line 41:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Example:
+
たとえば、次のようになる。
 
<syntaxhighlight>
 
<syntaxhighlight>
 
with Info do
 
with Info do
 
begin
 
begin
   Age := 18;
+
   age := 18;
   ZIP := 90210;
+
   zip := 90210;
 
end;
 
end;
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 08:55, 2 October 2015

Template:Records/ja

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, statezip のそれぞれはフィールドとして参照される。次のようにして変数内のフィールドにアクセスできる。

 変数識別子.フィールド識別子

ピリオドで変数とフィールド名を分ける。

レコード型を扱うときにとても便利な命令文がある。ひとつのレコード型変数を長く用いるつもりで、変数名を繰り返し繰り返しタイプしたくないなら、変数名を除いて、フィールド識別子だけを用いることができる。以下のようにすればよい。

WITH レコード型変数 DO
BEGIN
  ...
END;

たとえば、次のようになる。

with Info do
begin
  age := 18;
  zip := 90210;
end;
previous contents next