Sign in Join
Wiki copytemporary

Programming Using Classes: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Programming Using Classes

OldNewLine
1+## Using an Object Pascal Class
2+
3+To use a class one can either call class methods or create an instance of the class and then use it's fields, properties and methods.
4+
5+The instance of an Object Pascal class is commonly called "object", but don't confuse it with Object Pascal Objects. To create an instance of a class, one should call one of it's constructors. The constructor will return the instance of the class. Assign the returned instance to a variable in order to be able to use it and remember to free the instance later using the Free method. Descendents of TComponent can have an owner specified in their constructor. The instance will then be freed when the owner is freed and calling Free manually isn't necessary.
6+
7+The following examples demonstrates the syntax that can be used to create a class and access it's methods:
8+
9+``` pascal
10+var
11+ MyStringList: TStringList;
12+begin
13+ MyStringList := TStringList.Create;
14+ try
15+ MyStringList.LoadFromFile('path_to_my_file.txt');
16+ // ...
17+ finally
18+ MyStringList.Free;
19+ end;
20+end;
21+```
22+
23+## See Also
24+
25+- [[Object Oriented Programming with FreePascal and Lazarus]]
26+
27+---
28+*From the Free Pascal wiki, page "Programming Using Classes", as it stood on 2020-02-23 after a change by Trev, 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](/wiki-contact).*
29+Category: FPC
30+Category: Object-oriented development

Back to history