I am having problem with the logic. I have no idea how to copy record to another record in Delphi.
TypeA = record
value1 : word;
value2 : word;
value3 : word;
end;
TypeB = record
b1 : byte;
b2 : byte;
end;
I have my two records TypeA and TypeB. For example, I found out that data in TypeA record is belong to TypeB records. Note: TypeA has longer Data Length.
Question: How do i copy TypeA memory and place it in TypeB record?
CopyMemory(@TypeA, @TypeB, Length(TypeB))
When i tried CopyMemory and got an error (Incompaible types).
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.
Thanks in advance
----Addition question:
Is there a way to copy Delphi record to Byte array and how? If there is,
Will this logic work?
CopyMemory(@a, @b, SizeOf(TypeB))
if a
is of type TypeA
and b
is of type TypeB
.
Variant records:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With