Sign in Join
Wiki copytemporary

Revision 1 of 1, by WikiArchive on 11-4-2026. The page as it is now.

Programming Using Classes/ja

Object Pascal でクラスを用いる

クラスを使用するには、クラスメソッドを呼び出すか、クラスのインスタンスを作成してそのフィールド、プロパティ、メソッドを使用する。

Object Pascalクラスのインスタンスは一般的に 「object」 と呼ばれるが、Object PascalのObjectsとは異なることに注意してすること。クラスのインスタンスを作成するには、そのコンストラクタの1つを呼び出す必要がある。コンストラクタはクラスのインスタンスを返す。返されたインスタンスを変数に割り当てて使用できるようにし、後で Free メソッドを使用してインスタンスを解放することを忘れないこと。TComponentの派生クラスは、コンストラクタで所有者を指定できる。その場合、所有者が解放されるとインスタンスも解放され、手動で Free を呼び出す必要はない。

以下の例は、クラスを作成し、そのメソッドにアクセスするために使用できる構文を示しています:

pascal
var
  MyStringList: TStringList;
begin
  MyStringList := TStringList.Create;
  try
    MyStringList.LoadFromFile('path_to_my_file.txt');
    // ...
  finally
    MyStringList.Free;
  end;
end;

以下も参照のこと


From the Free Pascal wiki, page "Programming Using Classes/ja", as it stood on 2024-04-03 after a change by Ariben, 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.