我的定义
type
Surfer7GridHead=record
      HeaderSectionID_Id:integer; //Id for Header section
      HeaderSize:integer;     //Size of Header section
      HeaderVersion:integer;     //Header Section: Version
      GridSectionID:integer; //ID indicating a grid section
      GridSectionLength:integer; //Length in bytes of the grid section
      nRow:integer;
      nCol:integer;      xLL:Double; // X coordinate of the lower left corner of the grid
      yLL:Double; // Y coordinate of the lower left corner of the grid
      xSize:Double;  // spacing between adjacent nodes in the X direction (between columns)
      ySize:Double;   //spacing between adjacent nodes in the Y direction (between rows)
      zMin :Double;   //minimum Z value within the grid
      zMax :Double;   //maximum Z value within the grid
      Rotation:Double;    //not currently used
      BlankValue:Double;  //nodes are blanked if  greater or equal to this value      DataSectionID:integer;  //ID indicating a data section
      dataSectionlength:integer; //Length in bytes of the data section
      end;里面有8个double和9个integer  ,该Surfer7GridHead的大小应该是8*8+4*9=100
但我用sizeof()这函数出来一看,怎么是104
究竟我错了什么,望高人指点!!!

解决方案 »

  1.   

    integer占4个字节,double占8个字节。
    Surfer7GridHead这个存储结构应该是这样的:44 44 44 40 8 8 8 8 8 8 44 
    在0的地方它会自动补上4个字节。
    写一个简单的:
     type
       MyType=record
         a:integer;
         b:double;
       end;
    你用SizeOf(MyType)来看它的值,发现会是16而不是12,就是它会自动补上了4个字节。
      

  2.   

    或者在菜单 Project-->Options...-->Compiler-->Code generation-->Record field alignment选择1,默认是8
      

  3.   

    感谢楼上各位。如果不要对齐,加上packed就可以了。