C++的位段定义在DELPHI中怎么实现?(50)

C

citydawn

Guest
#1
typedef struct{DWORD dwStartCode;
// For one valid AvFrm, this always be AVFRM_START_CODEDWORD FrmType :2;
// enVidFrmTypeDWORD VidLen :18;
// Video data length, max 256kDWORD AudLen :12;
// Audio data length, max 4kDWORD dwFrmNum;
// Frame Number : 1 ~ TRecFileHead::dwTotalFrmCntBYTE Reserved[4];}TFrmHead;
// Total 16 bytes在C++中可定义位段DWORD FrmType :2;
// enVidFrmTypeDWORD VidLen :18;
// Video data length, max 256kDWORD AudLen :12;
// Audio data length, max 4k那么这样的定义在DELPHI中怎么实现?
 
Y

ysai

Guest
#2
D中没法定义,只能写方法读写D2010里record结构可以包含方法,比较好用
 

小雨哥

Guest
#3
好像无法在类型定义时直接给定默认值。常用的变通方法是把定义与赋值分开来:===========================================================================type TFrmHead = record dwStartCode: DWORD;
FrmType: DWORD;
VidLen: DWORD;
AudLen: DWORD;
dwFrmNum: DWORD;
Reserved: DWORD;
end;
var avFrameHead: TFrmHead = (dwStartCode:0;
// For one valid AvFrm, this always be AVFRM_START_CODE FrmType:2;
// enVidFrmType VidLen:18;
// Video data length, max 256k AudLen:12;
// Audio data length, max 4k dwFrmNum:0;
// Frame Number : 1 ~ TRecFileHead::dwTotalFrmCnt Reserved:0);
// Total 16 bytes??? -> Total 24 bytes !
 

地质灾害

Guest
#4
好像楼上的看错了DWORD FrmType :2;
// enVidFrmTypeDWORD VidLen :18;
// Video data length, max 256kDWORD AudLen :12;
// Audio data length, max 4k这3句不是给成员赋初值,而是定义FrmType,VidLen和AudLen这3个成员分别占用2bits,18bits和12bits。