I remember that when I used to set the C ++ header file, a member in the struct is defined as a bit field. To put it bluntly, what does each bit in a byte mean, for example, if the value of 3rd bits is 1, the data is valid. If the value of 0 is false, the data is invalid.
At that time, there was no way to define a byte directly. When using it, read the byte first and use the operation to judge it.
Recently, I am stuck at the junction of Xiangfan and Henan. It's a remote location. But you can check it out if you have nothing to do.CodeRight.
In fact, when I looked at the PAS file translated by Jedi a long time ago, I saw a bit field represented by set. At that time, I didn't care much about it. Today, when I was looking at the objauto unit, some new discoveries during the test:
// Parameter value passing method // tparamflag = (pfvar, pfconst, pfarray, pfaddress, pfreference, pfout, pfresult); tparamflags = set of tparamflag;
This is the set definition part. Let's take a look at our code.
Procedure tform3.btn1click (Sender: tobject); var P: tparamflags; begin P: = [pfreference]; P: = [pfvar, pfconst, pfarray, pfaddress, pfreference, pfout, pfresult] end;
If we use ord (pfvar), we can only get 0, and the prompt in Delphi shows 0, but here it is enclosed by []. Does the value change?
We can see that eax is $10 or 00010000, which is the value of [pfreference. when pfreference is set to 4, it turns to the fifth binary position, which is 1 or 16.
That is, in a collection, each element occupies one place, and the element are connected by or to form a number.
How big is a collection? In fact, it has a relationship with how many elements it has. The size should be divided into 8 + 1. See the example below:
In the above example, add
Showmessage (inttostr (sizeof (p )));
The result is 1, because tparamflag contains only seven elements.
Let's define a set with more elements,
Type ttest = (T1, T2, T3, T4, T5, T6, T7, T8, T9); Ttests = set of ttest; Procedure tform3.btn4click (Sender: tobject); var t: ttests; begin showmessage (inttostr (sizeof (t); end;
Now the result is 2.
After talking about this, the final thing is to judge whether a certain character is a struct or other time.
If T1 in t then
If it is true, The 0th-bit value is 1.
That's all you need to talk about.