以下的C结构如何改为Delphi的结构?谢谢!
struct __PACKET_BUFFER__
{
BYTE Status;
BYTE AclType;
BYTE NetType;
BYTE TimeType; ULONG AclId; union
{
struct
{
USHORT TcpCode : 6;
USHORT Reserved : 10;
};
struct
{
USHORT TcpFin : 1;
USHORT TcpSyn : 1;
USHORT TcpRst : 1;
USHORT TcpPsh : 1;
USHORT TcpAck : 1;
USHORT TcpUrg : 1; USHORT Direction : 1; // 0: IN, 1: OUT
USHORT SendOrRecv : 1;
USHORT Action : 8;
};
};
BYTE bReserved[2]; BYTE Protocol;
BYTE Week;
BYTE IcmpType;
BYTE IcmpSubType; ULONG Time;
ULONG SourceIp;
ULONG DestinationIp; union
{
ULONG Id;
struct
{
ULONG SourcePort : 16;
ULONG DestinationPort : 16;
};
}; ULONG DataBytes;
ULONG ProcessHandle; char sProcess[16];
};struct __PACKET_DIRECTION__
{
ULONG Id; struct
{
BYTE Direction : 4;
BYTE Action : 4;
}; BYTE NetType; struct
{
BYTE AclType : 4;
BYTE Reserved : 2;
BYTE DeleteIn : 1;
BYTE DeleteOut: 1;
}; BYTE Protocol; ULONG AclId;
ULONG Time;
ULONG ProcessHandle;
ULONG SendData;
ULONG RecvData;
ULONG LocalIp;
ULONG RemoteIp; USHORT LocalPort;
USHORT RemotePort; char sProcess[16];
};

解决方案 »

  1.   

    好像不可以直接修改为Delphi的结构,处理方法,将Union部分以及Struct定义为另外一个单独的结构Record类型, 然后在对应的部分用该结构类型作类型定义C中的例如
    struct
    {
    BYTE Direction : 4;
    BYTE Action : 4;
    };的结构定义在Delphi中可以使用掩码移位的方式解决,或定义一个类,内部使用结构,外部使用属性然后作转换
      

  2.   

    对于UNION部分可使用可变结构体
      

  3.   

    结构用type定义,联合用record来定义
      

  4.   

    // c
    struct CStruct{
      int x;
      union{
        int y;
        int z;
      }
    }
    // d
    TStruct = record
       x: Integer;
       case Integer of
         0: (y: Integer);
         1: (z: Integer);
    end;