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;
被纳闷一下午了..........

解决方案 »

  1.   

     memo1.Lines.Append(INttostr(Sizeof(ShortInt)));
      memo1.Lines.Append(INttostr(Sizeof(SmallInt)));
       memo1.Lines.Append(INttostr(Sizeof(Integer)));這樣算下吧,看得眼都花了。
      

  2.   

     TItemSDataInfo = packed 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; 這樣再來讀讀看。
      

  3.   


    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;
     幫你區分了下,呵呵
      

  4.   

    按ShortInt 1字节 SmallInt 2字节 Integer 4字节来算.应该是81个字节
    但是返回总是84字节
      

  5.   

      TItemSDataInfo = record
        nSpeed: ShortInt;
        nExp: ShortInt;
        nBuy: Integer;
        nSell: Integer;
        nGrade: SmallInt;
        nDrop: SmallInt;
        nServer: ShortInt;
        nCount: ShortInt;
      end;
    我试着一段一段SizeOf  这段返回是20字节
    但是我又单独把这段一行一行SizeOf 返回的是对的
    是什么原因呢?
      

  6.   

    上面的區分還不明白嗎?而且你手工去算都算錯了。這是因為數據對齊的問題。上面我寫的一個  packet record  就會是要要的結果。
    不然 Type Recprd   的話,按4個字節分配的話,就會出現你上面的情況。
      

  7.   

    说句题外话,你的record设计有问题
      

  8.   

    因为一直是自学.所以之前一直没注意record还有个同胞packed record
      

  9.   


    這裏我寫的: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   則會按各個字段的類型占用字節數去申請內存,就不會出現上面的問題。
      

  10.   


    shortint 理论上占用2个字节,实际上呢? 一个shortint站4个字节,2个shortint站4个字节,3个占8个,4个占8个 
    懂了吧,
    如果不这样 声明是加上packed  TItemSDataInfo = packed record
      
    end;
      

  11.   

    size of 确定返回的就是字节个数么?