tmessage的问题(关于记录类型)(100分)

  • 主题发起人 主题发起人 zhangwh
  • 开始时间 开始时间
Z

zhangwh

Unregistered / Unconfirmed
GUEST, unregistred user!
Tmessage的定义如下:

TMessage = record
Msg: Cardinal;
case Integer of
0: (
WParam: Longint;
LParam: Longint;
Result: Longint);
1: (
WParamLo: Word;
WParamHi: Word;
LParamLo: Word;
LParamHi: Word;
ResultLo: Word;
ResultHi: Word);
end;

在记录类型的可变部分一般都是这样定义的

case 识别字段标识符:识别字段类型 of
。。。。

可是这里却是用到类型 integer 没有标识符

该怎么理解,

在delphi中这种可变类型很多啊
 
这个相当于Pascal中union.
TMessage应该是packed record,而不是record.
如TRect等都是这么定义的.取值得时候你可以
用 WParam: Longint;
LParam: Longint;
Result: Longint 表示一个message
也可以用
WParamLo: Word;
WParamHi: Word;
LParamLo: Word;
LParamHi: Word;
ResultLo: Word;
ResultHi: Word 表示一个message

 
机理上的东西可以参考一下这段话:
This is a byte alignment issue. To ensure proper alignment of the fields in
an unpacked record type, the Delphi 3 compiler inserts an unused byte before
fields with an alignment of 2, and up to three unused bytes before fields with
an alignment of 4, if required. Finally, the compiler rounds the total size
of the record upwards to the byte boundary specified by the largest alignment
of any of the fields.

When a record type is declared in the {$A-} state, or when the declaration
includes the packed modifier, the fields of the record are not aligned, but
are instead assigned consecutive offsets. The total size of such a packed
record is simply the size of all the fields.

 
接受答案了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
724
import
I
I
回复
0
查看
416
import
I
后退
顶部