我正在尝试使用以下代码:https://github.com/hiro2233/mavlink_pascal
这是与RAD Studio Berlin一起写的。
它使用此功能:
CopyRecord(@msg_data_PARAM_VALUE, packet_data, TypeInfo(mavlink_param_value_t));
位置:
mavlink_param_value_t = record
param_value: Single;
param_count: Word;
param_index: Word;
param_id: array[0..15] of Byte;
param_type: Byte;
end;
msg_data_PARAM_VALUE:mavlink_param_value_t;
packet_data:System.TArray<System.Byte>;
我正在使用RAD Studio XE2,但无法识别此功能。
我尝试过在线查找,但找不到任何东西。
有人可以帮我弄清楚吗?
干杯,E。
仅使用System.Move()
代替:
System.Move()
所讨论的代码正在将字节从procedure THelpers.packet_msg_data_set(packet:System.TArray<System.Byte>; msg_id:UInt8; data_length:UInt8);
var
packet_data:System.TArray<System.Byte>;
begin
case msg_id of
MAVLINK_MSG_ID.MAVLINK_MSG_ID_PARAM_VALUE:
begin
//SetLength(packet_data, data_length); // <-- redundant!
packet_data:= Copy(packet,6,data_length);
//CopyRecord(@msg_data_PARAM_VALUE, packet_data, TypeInfo(mavlink_param_value_t));
Move(packet_data[0], msg_data_PARAM_VALUE, SizeOf(msg_data_PARAM_VALUE));
end;
MAVLINK_MSG_ID.MAVLINK_MSG_ID_HEARTBEAT:
begin
//SetLength(packet_data, data_length); // <-- redundant!
packet_data:= Copy(packet,6,data_length);
//CopyRecord(@msg_data_HEARTBEAT, packet_data, TypeInfo(mavlink_heartbeat_t));
Move(packet_data[0], msg_data_HEARTBEAT, SizeOf(msg_data_HEARTBEAT));
end;
end;
end;
复制到2个可能的TArray<Byte>
中的1个,并且这些record
中的所有字段仅是基本类型,不涉及指针或引用计数。因此,我不知道为什么作者选择使用record
依赖RTTI复制这些字节,该功能根本不应该直接使用。