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

我需要在Delphi中完成数组记录吗?

发布时间:2020-12-15 10:10:01 所属栏目:大数据 来源:网络整理
导读:在我的申请中我有以下记录: TTransaction = record Alias: string Description: string Creation: TDateTime Count: Integerend; 我在这个数组中使用这个记录: Transactions = array of TTransaction; 我在运行时保持阵列加载,但在给定的时间,我需要清除所
在我的申请中我有以下记录:
TTransaction = record
  Alias: string
  Description: string
  Creation: TDateTime
  Count: Integer
end;

我在这个数组中使用这个记录:

Transactions = array of TTransaction;

我在运行时保持阵列加载,但在给定的时间,我需要清除所有数据并添加一些新的.

是否足够使用:

SetLength(Transactions,0); ?

还是我需要确定一些东西?

解决方法

有三种方式来释放与动态数组的内存关联:a:
SetLength(a,0);
Finalize(a);
a := nil;

这取决于你使用哪一种.

documentation说的是一样的,虽然在时尚方面略显一圆:

To deallocate a dynamic array,assign nil to a variable that references the array or pass the variable to Finalize; either of these methods disposes of the array,provided there are no other references to it. Dynamic arrays are automatically released when their reference-count drops to zero. Dynamic arrays of length 0 have the value nil.

这将释放与数组关联的所有内存,包括由您的记录类型拥有的任何嵌套管理类型,如字符串,动态arrys等.

如果需要调整数组大小以备将来使用,并且可以使用新的数据,只需使用SetLength调整大小,并适当地初始化剩余的元素.

(编辑:李大同)

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

    推荐文章
      热点阅读