TSmallPoint (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example illustrates how to use different routines from TSmallPoint.

Code

uses
  System.SysUtils,
  System.Types;
var
  aSmallPoint1,aSmallPoint2,aSmallPoint3 : TSmallPoint;
  aDistance : Double;
begin
  aSmallPoint1.Create(1,2);
  writeln(aSmallPoint1.x,' ',aSmallPoint1.y);
  //The console will output:  1 2 , representing the coordonates for aSmallPoint1
  aSmallPoint2.Create(2,2);
  aDistance:= aSmallPoint1.Distance(aSmallPoint2);
  writeln(Format('%2.2f',[aDistance]));
  // The console will output:  1.00 , representing the distance between aSmallPoint1 and aSmallPoint2
  aSmallPoint3:=aSmallPoint1.Add(aSmallPoint2);
  writeln(aSmallPoint3.x,' ',aSmallPoint3.y);
  //The console will output:  3 4 , representing the coordonates for aSmallPoint1 after Add routine
  aSmallPoint3:=aSmallPoint1.Subtract(aSmallPoint2);
  writeln(aSmallPoint3.x,' ',aSmallPoint3.y);
  //The console will output:  -1 0 , representing the coordonates for aSmallPoint1 after Subtract routine
  writeln('');

  // For TSmallPoint was overloaded class operator Add, Subtract, Equal and we can use follow code
  aSmallPoint1.Create(1,2);
  aSmallPoint2.Create(2,2);
  aSmallPoint3:=aSmallPoint1 + aSmallPoint2;
  writeln(aSmallPoint3.x,' ',aSmallPoint3.y);
  //The console will output:  3 4 , representing the coordonates for aSmallPoint1 after Add routine
  aSmallPoint3:=aSmallPoint1 -  aSmallPoint2;
  writeln(aSmallPoint3.x,' ',aSmallPoint3.y);
  //The console will output:  -1 0 , representing the coordonates for aSmallPoint1 after Subtract routine
  writeln('');
  Readln;
end.


Uses