sMa*_*Mah 4 memory delphi copy record
我遇到逻辑问题.我不知道如何将记录复制到Delphi中的另一条记录.
TypeA = record
value1 : word;
value2 : word;
value3 : word;
end;
TypeB = record
b1 : byte;
b2 : byte;
end;
Run Code Online (Sandbox Code Playgroud)
我有两个记录TypeA和TypeB.例如,我发现TypeA记录中的数据属于TypeB记录.注意:TypeA具有更长的数据长度.
问题:如何复制TypeA内存并将其放在TypeB记录中?
CopyMemory(@TypeA, @TypeB, Length(TypeB))
Run Code Online (Sandbox Code Playgroud)
当我尝试CopyMemory并得到一个错误(无法比较的类型).
PS:我不想像下面那样复制或分配它.
TypeB.b1:= TypeA.value1 && $ FF;
TypeA和TypeB只是示例记录.大多数情况下,记录TypeA和TypeB可能包含多个记录,并且分配表单TypeA并分配给TypeB记录将更加困难.
提前致谢
----加法问题:
有没有办法将Delphi记录复制到Byte数组以及如何?如果有,
这个逻辑会起作用吗?
CopyMemory(@a, @b, SizeOf(TypeB))
Run Code Online (Sandbox Code Playgroud)
if a是类型TypeA和b类型TypeB.
变体记录:
TypeA = packed record
value1 : word;
value2 : word;
value3 : word;
end;
TypeB = packed record
b1 : byte;
b2 : byte;
end;
TypeAB = packed record
case boolean of
false:(a:TypeA);
true:(b:TypeB);
end;
..
..
var someRec:TypeAB;
anotherRec:TypeAB;
..
..
anotherRec.b:=someRec.b
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12410 次 |
| 最近记录: |