delphi5的结构成员缺省是按照多少字节对齐的?
delphi6可以在编译选项中选择,delphi5怎么办?
因为有一DLL的参数是结构,而DLL的对齐方式是1字节的.

解决方案 »

  1.   

    Type Switch
    Syntax {$A+}, {$A-}, {$A1}, {$A2}, {$A4}, or {$A8}
    {$ALIGN ON}, {$ALIGN OFF}, {$ALIGN 1}, {$ALIGN 2}, {$ALIGN 4}, or {$ALIGN 8}
    Default {$A8}
    {$ALIGN 8}
    Scope Local
    ResThe $A directive controls alignment of fields in Delphi record types and class structures.
    In the {$A1} or {$A-} state, fields are never aligned. All record and class structures are packed.
    In the {$A2} state, fields in record types that are declared without the packed modifier and fields in class structures are aligned on word boundaries.
    In the {$A4} state, fields in record types that are declared without the packed modifier and fields in class structures are aligned on double-word boundaries.In the {$A8} or {$A+} state, fields in record types that are declared without the packed modifier and fields in class structures are aligned on quad word boundaries.
    Record type field alignment is described in the Delphi Language Guide. See Record types.
    Regardless of the state of the $A directive, variables and typed constants are always aligned for optimal access. In the {$A8} state, execution will be faster.
      

  2.   

    按里面字节最大的成员分量对齐的。
    比如你声明了一个boolean,byte,intger,word,就是四个字节(intger最大),
    如果没有intger就是两个字节(word最大).
      

  3.   

    谢谢各位!!!!!
    to outer2000:
    能否写个具体例子,如何定义?这种方法没用过,惭愧.
    谢谢.
      

  4.   

    若是1字节对齐很好办, 也不用设置对齐开关.
    type
       TByteAlign = packed record
          A: Byte;
          B: Word;
          C: Integer;
       end;只要在 record 前加 packed 即可.SizeOf(TByteAlign) = 7;
    若去掉 packed, 则 SizeOf(TByteAlign) = 8;