在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
unit Unit1; {$DEFINE USESGUIDHELP} interface implementation {$IFDEF USESGUIDHELP} uses System.SysUtils; {$ENDIF} procedure test; var a:TGUID;//System单元 begin {$IFDEF USEGUIDHELP} a.NewGuid //调用System.SysUtils.TGuidHelper a.Create() //调用System.SysUtils.TGuidHelper {$ENDIF} end;
PGUID = ^TGUID; TGUID = packed record D1: LongWord; D2: Word; D3: Word; D4: array[0..7] of Byte; class operator Equal(const Left, Right: TGUID): Boolean; class operator NotEqual(const Left, Right: TGUID): Boolean; class function Empty: TGUID; static; end; type TGuidHelper = record helper for TGUID class function Create(const B: TBytes): TGUID; overload; static; class function Create(const S: string): TGUID; overload; static; class function Create(A: Integer; B: SmallInt; C: SmallInt; const D: TBytes): TGUID; overload; static; class function Create(A: Integer; B: SmallInt; C: SmallInt; D, E, F, G, H, I, J, K: Byte): TGUID; overload; static; class function Create(A: Cardinal; B: Word; C: Word; D, E, F, G, H, I, J, K: Byte): TGUID; overload; static; class function NewGuid: TGUID; static; function ToByteArray: TBytes; function ToString: string; end;
1、Record不支持继承,使用Helper间接是完成了继承 2、将Record分别在各自的单元(命名空间下),可选择的使用Helper,即可在不影响原调用的情况下,在扩展代码中使用Helper的方法,也可以无需修改原Record或class定义而直接覆盖它们中的方法。
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论