加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – 我可以为TBytes定义记录助手吗?

发布时间:2020-12-15 09:51:16 所属栏目:大数据 来源:网络整理
导读:我正在使用Delphi XE4.我尝试为TBytes定义一些辅助函数: TBytesHelper = record helper for TBytespublic function GetLength: integer;end;function TBytesHelper.GetLength: integer;begin Result := System.Length(Self);end; 当我尝试使用新的辅助函数
我正在使用Delphi XE4.我尝试为TBytes定义一些辅助函数:

TBytesHelper = record helper for TBytes
public
  function GetLength: integer;
end;

function TBytesHelper.GetLength: integer;
begin
  Result := System.Length(Self);
end;

当我尝试使用新的辅助函数时:

var B: TBytes;
    i: integer;
begin
  B := TBytes.Create(1,2,3);
  i := B.GetLength;

  if i <> Length(B) then
    raise Exception.Create('Incorrect result');
end;

我除了结果我是3但它没有.我在SysUtils.pas中引用具有类似构造的TStringHelper定义.

有什么我想念的吗?

解决方法

这里讨论了这个问题:
https://forums.embarcadero.com/thread.jspa?threadID=88409
简而言之 – 您可以定义自己的类型并将其与记录助手一起使用:

type
 TMyBytes = array of Byte;

 TBytesHelper = record helper for TMyBytes
   function GetLength: integer;
 end;

但它不适用于Delphi中定义的TBytes.最近添加了对泛型类型的帮助程序的支持,因此它可能是当前实现的一种限制.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读