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;
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;
bit7: UINT;
bit6: UINT;
bit5: UINT;
bit4: UINT;
bit3: UINT;
bit2: UINT;
bit1: UINT;
bit0: UINT;
end;
Object Pascal中没有联合的呀。
各位,能否给我一个具体的答案?
bits.Size:=8;
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 操作进行位运算。