c语言中下面这个结构怎么翻译成object PASCAL(Delphi)的对应结构
typedef struct tagBITS
{
   UINT bit7 : 1;
   UINT bit6 : 1;
   UINT bit5 : 1;
   UINT bit4 : 1;
   UINT bit3 : 1;
   UINT bit2 : 1;
   UINT bit1 : 1;
   UINT bit0 : 1;
}BITS;

解决方案 »

  1.   

    type BITS = Record
       bit7: UINT;
       bit6: UINT;
       bit5: UINT;
       bit4: UINT;
       bit3: UINT;
       bit2: UINT;
       bit1: UINT;
       bit0: UINT;
    end;
      

  2.   

    你那个结构是C/C++特有的位域结构,Delphi好像没有这样的,但是你可以使用Delphi中的联合来节约空间,C/C++中的这个位域存在的目的也就是为了节约空间,你用联合就可以了
      

  3.   

    联合——是指变体记录吧?
    Object Pascal中没有联合的呀。
      

  4.   

    我指的是delphi,呵呵,表错意了,不一定非要object pascal
    各位,能否给我一个具体的答案?
      

  5.   

    用类 TBits  定义一个对象 bits:TBits  bits:=tbits.Create;
      bits.Size:=8;
      

  6.   

    TBits不行那。procedure TForm1.Button2Click(Sender: TObject);
    var
      Bit: TBits;
      I: Integer;
    begin
      Bit := TBits.Create;
      try
        Bit.Size := 8;
        for I := 0 to 7 do
          Bit[I] := False;
        for I := 0 to 7 do
        begin
          Bit.Bits[I] := True;
          // 按C++的意思,出来应该是: 
          // 1, 1 + 2 = 3, 1+2+4=7, 1+2+4+8=15 .... 
          // 而这里出来则是:1, 2, 3, 4, 5...
          Memo1.Lines.Add(IntTOStr(Bit.OpenBit));
        end;
      finally
        Bit.Free;
      end;
    end;像C++这里,只是译成:
    type
      BITS = record
        Flags: UINT;
      end;然后在Flags中包含了32位数据,通过or 和 and 操作进行位运算。