Property

This section covers the definition, syntax, specifications and serialization of Properties What is a Property property is syntactic sugar in Pascal. Externally it behaves like a field, but internally it …

is and as Summary

Pascal/FPC is Type Check, as Safe Cast, TClass(X) Unchecked Raw Cast Usage of is and as 1 is Operator: Runtime Type Detection Check whether an object instance belongs to a …

Constructors and Destructors

Class, Class Instance, Constructor, Destructor The example above includes TAnimal and its subclass TDog. A class is merely a type, which can be understood as a template. The class itself …

Inheritance and Virtual Methods

Inheritance, Virtual Methods, override, reintroduce Example of Class Inheritance Object Pascal supports inheritance and virtual methods. In the example below, TDog inherits from TAnimal: TDog is the derived class (subclass), …

What Is a Class

Object Pascal supports classes A class is a container that holds the following members Classes can also contain other types of members, which will be covered later. Classes are a …

Expose Legacy Units

Expose identifiers from other units through a new unit Sometimes you need to re-export and expose identifiers from another unit within your new current unit. The end result: as long …

Unit-Qualified Identifiers

Similar to namespaces in C++, Java and C# Conflicts of Identifiers with Identical Names Multiple units may define types / functions / variables sharing the same name. Units placed later …

Initialization and finalization

A Unit can also contain an initialization section and a finalization section. These two blocks of code run automatically when the program starts and exits respectively. initialization: Executes when the …

Units

A Unit packages shared type declarations, functions, procedures, constants, variables and more for invocation by other units or the main program, equivalent to modules / packages in other programming languages. …

Numeric to string conversion

If you don’t want to print directly but concatenate any number of variables into a complete string, Pascal offers three mainstream implementation methods: Concatenation via Dedicated Conversion Functions ***ToStr + …

Output & Logging

Console Output Write / WriteLn To print strings in Pascal, use the built-in procedures Write or WriteLn; WriteLn automatically appends a line break at the end. This is an extremely …

Loop

Four types of loops: for / while / repeat / for-in Refer to the examples below first. Modify the code file from the previous lesson, mydemo.dpr, and change its extension …

Enum Arrays vs Sets

Ordinal Types as Array Subscripts Constant-length arrays Enumerations and custom range ordinal types can be used as array subscripts, allowing flexible customization of array index ranges. Example: Enums as Array …

Enumerated Type

1. Enumerated Type Pascal enums are well-encapsulated opaque types and used far more frequently in day-to-day development than enums from other programming languages. Basic Declaration Syntax Coding convention: Prefix enum …

if conditional judgment

Use if .. then or if .. then .. else to run corresponding code when the condition is true. Unlike C-style languages: the conditional expression in Pascal does not need …