type
TpersonRec = record
ID: Integer;
case Boolean of //这个条件是什么意思,具体怎么用呢?请举一个例子,谢谢
True: (A: integer);
False: (B: Word);
end;
TpersonRec = record
ID: Integer;
case Boolean of //这个条件是什么意思,具体怎么用呢?请举一个例子,谢谢
True: (A: integer);
False: (B: Word);
end;
typedef struct {
int ID;
union {
int A;
unsigned short B;
};
}TpersonRec;
type
TpersonRec = record
ID: Integer;
case Boolean of //这个条件是什么意思,具体怎么用呢?请举一个例子,谢谢
True: (A: integer);
False: (B: Word);
end;var p :TpersonRec ;p.A := 12;ShowMessage(IntToStr(p.B)); //显示12
因为A B 二者是存储在同一个物理地址
var
V: TpersonRec;
begin
V.A := $ABCD1234;
ShowMessageFmt('A=%.8X, B=%.8X', [V.A, V.B]);
V.A := $00001234;
ShowMessageFmt('A=%.8X, B=%.8X', [V.A, V.B]);
V.A := $ABCD0000;
ShowMessageFmt('A=%.8X, B=%.8X', [V.A, V.B]);
end;共用体,也就是A,B共同使用一个内存,以上例子说明
至于case XType of
只是Delphi的语法问题,表示下面的数据是变体
也可以写成:
case Integer of
0: (a: Integer);
1: (b: Word);
...