RTL.ComplexNumbers Sample

From RAD Studio Code Examples
Jump to: navigation, search

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:
    • You can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.


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

  1. Navigate to Start | Programs | Embarcadero RAD Studio Athens | Samples and open Win32OperatorOverload.dproj.
  2. Press F9 or choose Run > Run.


The project has two source files:

File Contains


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.


See Also