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

Delphi内存拷贝与记录到另一个记录

发布时间:2020-12-15 09:44:31 所属栏目:大数据 来源:网络整理
导读:我遇到逻辑问题.我不知道如何将记录复制到Delphi中的另一条记录. TypeA = record value1 : word; value2 : word; value3 : word; end;TypeB = record b1 : byte; b2 : byte; end; 我有两个记录TypeA和TypeB.例如,我发现TypeA记录中的数据属于TypeB记录.注意
我遇到逻辑问题.我不知道如何将记录复制到Delphi中的另一条记录.

TypeA = record
  value1 : word;
  value2 : word;
  value3 : word;
  end;

TypeB = record
  b1 : byte;
  b2 : byte;    
  end;

我有两个记录TypeA和TypeB.例如,我发现TypeA记录中的数据属于TypeB记录.注意:TypeA具有更长的数据长度.

问题:如何复制TypeA内存并将其放在TypeB记录中?

CopyMemory(@TypeA,@TypeB,Length(TypeB))

当我尝试CopyMemory并得到一个错误(无法比较的类型).

PS: I don’t want to copy or assign it like below.

TypeB.b1 := TypeA.value1 && $FF;

TypeA and TypeB are just example records. Most of thecases,record TypeA and TypeB may contain multple records and it
will be harder to allocate form TypeA and assign to TypeB record.

提前致谢

—-加法问题:

有没有办法将Delphi记录复制到Byte数组以及如何?如果有,

> TypeA记录到字节数组
>字节数组到B类

这个逻辑会起作用吗?

解决方法

CopyMemory(@a,@b,SizeOf(TypeB))

如果a是TypeA类型而b是TypeB类型.

(编辑:李大同)

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

    推荐文章
      热点阅读