This sample demonstrates various features of records.
You can find the ComplexNumbers sample project at:
- Start > Programs > Embarcadero RAD Studio > Samples > Delphi > RTL > ComplexNumbers
- Subversion Repository for Delphi: http://sourceforge.net/p/radstudiodemos/code/HEAD/tree/branches/RADStudio_Rio/Object%20Pascal/RTL/ComplexNumbers/
This application provides an implementation for a record that handles complex numbers. It exemplifies operator overloading, visibility specifiers, instance methods, class methods, and class variables.
How to Use the Sample
- Navigate to Start | Programs | Embarcadero RAD Studio Rio | Samples and open Win32OperatorOverload.dproj.
- Press F9 or choose Run > Run.
The project has two source files:
The implementation for TComplex, a record that handles complex numbers.
A program that uses TComplex instances, operators, and methods.
TComplex implements a record that manages complex numbers. It provides fields, operators, instance methods, class methods, and class variables for operations with complex numbers.
- A constructor is simulated by using a private class procedure and the initialization section of the unit.
- The TComplex class overloads some of the Delphi operators: Add, Substract, Multiply, Divide, Negative, Equal, NotEqual, and so on.
- TComplex contains class variables, like Symbol and SymbolBeforeImaginary, that belong to the entire class and not to individual instances.
- TComplex implements both class methods (for example
class function From(const AReal, AImaginary: Double): TComplex; static;) and instance methods, for example
function ToString: System.String;.
- Members of TComplex have different visibility specifiers: strict private, private, and public.