_arrayName_
: The name of the array that identifies the array.
_subscript_
: The index of the array; subscript can be of any ordinal type. The array subscript cannot be real.
_dataType_
: The data type of the elements of the array.
Classes
Pascal allows for the creation of classes that serve as a model or template for generating objects with distinct characteristics and functions. A class outlines a collection of features and actions that describe the traits and operations of any object derived from that class.
Whenever you create an object from a class, you’re producing an instance of that class with unique behavior and property values. With classes, you can produce numerous instances of the same class, each with its own distinct set of property values and behavior.
Classes offer a vital mechanism for organizing code in more significant programs. They allow you to bundle together relevant data and actions into a solitary entity that can be reused across your code. By defining a class once and creating multiple instances of it, you can prevent code repetition and create more modular programs that are easier to maintain.
Array properties of a class
In Pascal, when you define an array as a property of a class, you should declare the array as a private field within the class. A private field can only be accessed by the class itself and its methods but not by other code outside the class. This helps to maintain the encapsulation of the class, which means that the internal workings of the class are hidden from external code.
After declaring the array as a private field, you can make it accessible from outside the class by exposing it as public property. A property is a programming construct that provides a way to read, write, or modify the value of a field or object member. In Pascal, you use the property keyword to define a property.
To define a public property that exposes the array as a readable and writable member of the class, you can specify the data type of the array within the property declaration. You can also define additional behavior or restrictions on the property, such as validating input values or triggering events when the property value changes.
By exposing the array as a public property, you allow other code outside the class to access and modify its contents without exposing the class’s internal workings. This helps maintain the integrity of the class design and makes it easier to reuse the class in different contexts.
Coding example
Here’s an example of how to define an array property of a class in Pascal: