TItemSDataInfo = record
nType: ShortInt;
nTypeID: ShortInt;
n1: SmallInt;
nReqlevel: SmallInt;
nCountry: ShortInt;
nAttackfighter: ShortInt;
nDefensefighter: ShortInt;
nPatrolrogue: ShortInt;
nShootrogue: ShortInt;
nAttackmage: ShortInt;
nDefensemage: ShortInt;
nGrow: ShortInt;
//n2: SmallInt;
nReqStr: SmallInt;
nReqDex: SmallInt;
nReqRec: SmallInt;
nReqInt: SmallInt;
nReqWis: SmallInt;
nReqluc: SmallInt;
nReqVg: SmallInt;
nReqOg: ShortInt;
nReqIg: ShortInt;
//nRange: SmallInt;
nRange: ShortInt;
nAttackTime: ShortInt;
nAttrib: ShortInt;
nSpecial: ShortInt;
nSlot: ShortInt;
nQuality: SmallInt;
nEffect: SmallInt;
nEffect2: SmallInt;
nEffect3: SmallInt;
nEffect4: SmallInt;
nConstHP: SmallInt;
nConstSP: SmallInt;
nConstMP: SmallInt;
nConstStr: SmallInt;
nConstDex: SmallInt;
nConstRec: SmallInt;
nConstInt: SmallInt;
nConstWis: SmallInt;
nConstLuc: SmallInt;
nSpeed: ShortInt;
nExp: ShortInt;
nBuy: Integer;
nSell: Integer;
nGrade: SmallInt;
nDrop: SmallInt;
nServer: ShortInt;
nCount: ShortInt;
end;
被纳闷一下午了..........
nType: ShortInt;
nTypeID: ShortInt;
n1: SmallInt;
nReqlevel: SmallInt;
nCountry: ShortInt;
nAttackfighter: ShortInt;
nDefensefighter: ShortInt;
nPatrolrogue: ShortInt;
nShootrogue: ShortInt;
nAttackmage: ShortInt;
nDefensemage: ShortInt;
nGrow: ShortInt;
//n2: SmallInt;
nReqStr: SmallInt;
nReqDex: SmallInt;
nReqRec: SmallInt;
nReqInt: SmallInt;
nReqWis: SmallInt;
nReqluc: SmallInt;
nReqVg: SmallInt;
nReqOg: ShortInt;
nReqIg: ShortInt;
//nRange: SmallInt;
nRange: ShortInt;
nAttackTime: ShortInt;
nAttrib: ShortInt;
nSpecial: ShortInt;
nSlot: ShortInt;
nQuality: SmallInt;
nEffect: SmallInt;
nEffect2: SmallInt;
nEffect3: SmallInt;
nEffect4: SmallInt;
nConstHP: SmallInt;
nConstSP: SmallInt;
nConstMP: SmallInt;
nConstStr: SmallInt;
nConstDex: SmallInt;
nConstRec: SmallInt;
nConstInt: SmallInt;
nConstWis: SmallInt;
nConstLuc: SmallInt;
nSpeed: ShortInt;
nExp: ShortInt;
nBuy: Integer;
nSell: Integer;
nGrade: SmallInt;
nDrop: SmallInt;
nServer: ShortInt;
nCount: ShortInt;
end;
被纳闷一下午了..........
memo1.Lines.Append(INttostr(Sizeof(SmallInt)));
memo1.Lines.Append(INttostr(Sizeof(Integer)));這樣算下吧,看得眼都花了。
nType: ShortInt;
nTypeID: ShortInt;
n1: SmallInt;
nReqlevel: SmallInt;
nCountry: ShortInt;
nAttackfighter: ShortInt;
nDefensefighter: ShortInt;
nPatrolrogue: ShortInt;
nShootrogue: ShortInt;
nAttackmage: ShortInt;
nDefensemage: ShortInt;
nGrow: ShortInt;
//n2: SmallInt;
nReqStr: SmallInt;
nReqDex: SmallInt;
nReqRec: SmallInt;
nReqInt: SmallInt;
nReqWis: SmallInt;
nReqluc: SmallInt;
nReqVg: SmallInt;
nReqOg: ShortInt;
nReqIg: ShortInt;
//nRange: SmallInt;
nRange: ShortInt;
nAttackTime: ShortInt;
nAttrib: ShortInt;
nSpecial: ShortInt;
nSlot: ShortInt;
nQuality: SmallInt;
nEffect: SmallInt;
nEffect2: SmallInt;
nEffect3: SmallInt;
nEffect4: SmallInt;
nConstHP: SmallInt;
nConstSP: SmallInt;
nConstMP: SmallInt;
nConstStr: SmallInt;
nConstDex: SmallInt;
nConstRec: SmallInt;
nConstInt: SmallInt;
nConstWis: SmallInt;
nConstLuc: SmallInt;
nSpeed: ShortInt;
nExp: ShortInt;
nBuy: Integer;
nSell: Integer;
nGrade: SmallInt;
nDrop: SmallInt;
nServer: ShortInt;
nCount: ShortInt;
end; 這樣再來讀讀看。
type
TItemSDataInfo = record
nType: ShortInt;
nTypeID: ShortInt;
n1: SmallInt;
nReqlevel: SmallInt;
nCountry: ShortInt;
nAttackfighter: ShortInt;
nDefensefighter: ShortInt;
nPatrolrogue: ShortInt;
nShootrogue: ShortInt;
nAttackmage: ShortInt;
nDefensemage: ShortInt;
nGrow: ShortInt;
//n2: SmallInt;
nReqStr: SmallInt;
nReqDex: SmallInt;
nReqRec: SmallInt;
nReqInt: SmallInt;
nReqWis: SmallInt;
nReqluc: SmallInt;
nReqVg: SmallInt;
nReqOg: ShortInt;
nReqIg: ShortInt;
//nRange: SmallInt;
nRange: ShortInt;
nAttackTime: ShortInt; nAttrib: ShortInt;
nSpecial: ShortInt;
nSlot: ShortInt;
//浪費 1 個
nQuality: SmallInt;
nEffect: SmallInt;
nEffect2: SmallInt;
nEffect3: SmallInt;
nEffect4: SmallInt;
nConstHP: SmallInt;
nConstSP: SmallInt;
nConstMP: SmallInt;
nConstStr: SmallInt;
nConstDex: SmallInt;
nConstRec: SmallInt;
nConstInt: SmallInt;
nConstWis: SmallInt;
nConstLuc: SmallInt;
nSpeed: ShortInt;
nExp: ShortInt;
//浪費 2個
nBuy: Integer;
nSell: Integer;
nGrade: SmallInt;
nDrop: SmallInt;
nServer: ShortInt;
nCount: ShortInt;
//浪費2個
end;
幫你區分了下,呵呵
但是返回总是84字节
nSpeed: ShortInt;
nExp: ShortInt;
nBuy: Integer;
nSell: Integer;
nGrade: SmallInt;
nDrop: SmallInt;
nServer: ShortInt;
nCount: ShortInt;
end;
我试着一段一段SizeOf 这段返回是20字节
但是我又单独把这段一行一行SizeOf 返回的是对的
是什么原因呢?
不然 Type Recprd 的話,按4個字節分配的話,就會出現你上面的情況。
這裏我寫的:type
TItemSDataInfo = record
nSpeed: ShortInt;
nExp: ShortInt;
nGrade: SmallInt; nBuy: Integer;
nSell: Integer; nDrop: SmallInt;
nServer: ShortInt;
nCount: ShortInt;
end;
這是你寫的:
TItemSDataInfo = record
nSpeed: ShortInt;
nExp: ShortInt;
nBuy: Integer;
nSell: Integer;
nGrade: SmallInt;
nDrop: SmallInt;
nServer: ShortInt;
nCount: ShortInt;
end;
看下各個變量的位置,要按4個字節去數據對齊明白了嗎??
如果你用 type Packet Record 則會按各個字段的類型占用字節數去申請內存,就不會出現上面的問題。
shortint 理论上占用2个字节,实际上呢? 一个shortint站4个字节,2个shortint站4个字节,3个占8个,4个占8个
懂了吧,
如果不这样 声明是加上packed TItemSDataInfo = packed record
end;