delphi operator overloading

For example, the above record can be declared as:

type
  TMyRec = record
    name: string;
    age: Word;
    class operator GreaterThan(a,b: TMyRec): Boolean;
  end;


But also a realization of (unfortunately some are not + Shift + C automatically created with Ctrl, then copy it):

class  operator TMyRec.GreaterThan (A, B: TMyRec): Boolean; {add note after copying method name: "TMyRec."} 
the begin 
  the Result: = a.age> b.age; End ;

 

Delphi for Win32 supports only type record operator overloading, but also supports Delphi .NET class type of operator overloading
The following can be supported Delphi operator overloading

Operator application type declaration syntax notation
Implicit Conversion Implicit (a: type): resultType ; implicit conversion

Explicit Conversion Explicit (a: type): resultType; explicit conversion

Unary minus Negative (a: type): resultType; -

N Unary Positive (a: type): resultType; +

Unary increment Inc (a: type): resultType; Inc

Unary decrement Dec (a: type): resultType; Dec

Logical NOT unary LogicalNot (a: type): resultType; not

Bitwise NOT unary BitwiseNot (a: type): resultType; not

Taken unary Trunc (a: type): resultType; Trunc

Rounding unary operation Round (a: type): resultType; Round

Equal to the comparison Equal (a: type; b: type): Boolean; =

Is not equal to comparison NotEqual (a: type; b: type): Boolean; <>

Greater-than comparison GreaterThan (a: type; b: type) Boolean;>

Greater than or equal comparison GreaterThanOrEqual (a: type; b: type): resultType;> =

Smaller than the comparison LessThan (a: type; b: type): resultType; <

Comparison less LessThanOrEqual (a: type; b: type): resultType; <=

Plus binary operation Add (a: type; b: type): resultType; +

Save binary operation Subtract (a: type; b: type): resultType; -

By binary operation Multiply (a: type; b: type): resultType; *

In addition to the binary operation Divide (a: type; b: type): resultType; /

Divisible binary operation IntDivide (a: type; b: type): resultType; div

Binary operation modulus Modulus (a: type; b: type): resultType; mod

Left binary operation ShiftLeft (a: type; b: type): resultType; shl

Right binary operation ShiftRight (a: type; b: type): resultType; shr

Logic and binary operation LogicalAnd (a: type; b: type): resultType; and

Or a logical binary operation LogicalOr (a: type; b: type): resultType; or

Logical XOR binary operation LogicalXor (a: type; b: type): resultType; xor

Bitwise binary operation BitwiseAnd (a: type; b: type): resultType; and

Bitwise binary operator or BitwiseOr (a: type; b: type): resultType; or

Bitwise XOR binary operation BitwiseXor (a: type; b: type): resultType; xor

Guess you like

Origin www.cnblogs.com/h2zZhou/p/11444600.html