譬如上面的 record 可以这样声明:

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

还得有方法的实现(遗憾的是有些不能用 Ctrl+Shift+C 自动建立, 那就复制吧):

class operator TMyRec.GreaterThan(a,b: TMyRec): Boolean; {注意复制后再加上方法名: "TMyRec."}
begin
  Result := a.age > b.age;
end;

Delphi for Win32 只支持 record 类型的运算符重载,而 Delphi .NET 还支持 class 类型的运算符重载
下面是Delphi支持的可重载运算符

运算符       类型       声明语法                                          应用符号
Implicit     转换       Implicit(a: type): resultType;                    隐式转换

Explicit     转换       Explicit(a: type): resultType;                    显式转换

负           一元运算   Negative(a: type): resultType;                    -

正           一元运算   Positive(a: type): resultType;                    +

递增         一元运算   Inc(a: type): resultType;                         Inc

递减         一元运算   Dec(a: type): resultType;                         Dec

逻辑非       一元运算   LogicalNot(a: type): resultType;                  not

按位非       一元运算   BitwiseNot(a: type): resultType;                  not

截取         一元运算   Trunc(a: type): resultType;                       Trunc

舍入         一元运算   Round(a: type): resultType;                       Round

等于         比较       Equal(a: type; b: type) : Boolean;                =

不等于       比较       NotEqual(a: type; b: type): Boolean;              <>

大于         比较       GreaterThan(a: type; b: type) Boolean;            >

大于等于     比较       GreaterThanOrEqual(a: type; b: type): resultType;>=

小于         比较       LessThan(a: type; b: type): resultType;           <

小于等于     比较       LessThanOrEqual(a: type; b: type): resultType;    <=

加           二元运算   Add(a: type; b: type): resultType;                +

减           二元运算   Subtract(a: type; b: type): resultType;           -

乘           二元运算   Multiply(a: type; b: type): resultType;           *

除           二元运算   Divide(a: type; b: type): resultType;             /

整除         二元运算   IntDivide(a: type; b: type): resultType;          div

模           二元运算   Modulus(a: type; b: type): resultType;            mod

左移         二元运算   ShiftLeft(a: type; b: type): resultType;          shl

右移         二元运算   ShiftRight(a: type; b: type): resultType;         shr

逻辑与       二元运算   LogicalAnd(a: type; b: type): resultType;         and

逻辑或       二元运算   LogicalOr(a: type; b: type): resultType;          or

逻辑异或     二元运算   LogicalXor(a: type; b: type): resultType;         xor

按位与       二元运算   BitwiseAnd(a: type; b: type): resultType;         and

按位或       二元运算   BitwiseOr(a: type; b: type): resultType;          or

按位异或     二元运算   BitwiseXor(a: type; b: type): resultType;         xor

最新文章

  1. [EasyUI美化换肤]更换EasyUi图标
  2. IOS - 控件的AutoresizingMask属性
  3. wp8 入门到精通 定时更新瓷贴
  4. SQUID之cache_peer
  5. sql server 2008 修改sa密码
  6. 0、IOS8:Xcode6 playground
  7. thead、tbody、tfoot与顺序无关
  8. [转]学DSP、FPGA、ARM,哪个更有前途?
  9. Hbase Region Server 启动失败
  10. Java基础(3) -字符串
  11. Yii小部件
  12. 【linux】安装mysql出现 no curses错误解决方法
  13. Day3 《机器学习》第三章学习笔记
  14. 测试highlightjs主题1
  15. Java编程思想--控制执行流程
  16. 《Redis开发与运维》读书笔记
  17. python 中文报错
  18. 第六篇-以隐式意图(Implicit Intent)呼叫系统服务
  19. 导入其他python文件或者python文件的函数
  20. roadhog resolve alias 绝对路径 别名使用

热门文章

  1. linux下安装dotnet core
  2. TypeScript_基础数据类型
  3. Android笔记(六十八) Fragment总结
  4. 阿里云ECS部署maven项目
  5. 搭建MySQL MMM高可用
  6. PAT上机注意事项
  7. Murach ASP.NET 4.5 C# With Visual Studio 2013 翻译
  8. Spring -12 -声明式事务及完整的XML配置文件信息 -声明式事务中的相关属性(tx:advice的标签)
  9. Div+CSS总结
  10. DELL--R420 CPU报警&ldquo;CPU0000 cpu2 internal error (IERR)contact support&rdquo;