Programming Using Classes/ja
English · 日本語
Object Pascal でクラスを用いる
クラスを使用するには、クラスメソッドを呼び出すか、クラスのインスタンスを作成してそのフィールド、プロパティ、メソッドを使用する。
Object Pascalクラスのインスタンスは一般的に 「object」 と呼ばれるが、Object PascalのObjectsとは異なることに注意してすること。クラスのインスタンスを作成するには、そのコンストラクタの1つを呼び出す必要がある。コンストラクタはクラスのインスタンスを返す。返されたインスタンスを変数に割り当てて使用できるようにし、後で Free メソッドを使用してインスタンスを解放することを忘れないこと。TComponentの派生クラスは、コンストラクタで所有者を指定できる。その場合、所有者が解放されるとインスタンスも解放され、手動で Free を呼び出す必要はない。
以下の例は、クラスを作成し、そのメソッドにアクセスするために使用できる構文を示しています:
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.
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.
