unit Graphics;TResource = record
Next: PResource;
RefCount: Integer;
Handle: THandle;
HashCode: Word;
case Integer of // 怎么理解?
0: (Data: TResData);
1: (Font: TFontData);
2: (Pen: TPenData);
3: (Brush: TBrushData);
end;
Next: PResource;
RefCount: Integer;
Handle: THandle;
HashCode: Word;
case Integer of // 怎么理解?
0: (Data: TResData);
1: (Font: TFontData);
2: (Pen: TPenData);
3: (Brush: TBrushData);
end;
解决方案 »
- Pascal编译器选择
- 有人散分吗
- 急:如何通过查询,将数据表中的记录为数字的列转化为相应的文字,于DBGrid中显示
- delphi如何改变系统的分辨率?
- ★我用sql语句删除adods_qdzm数据集中的记录,为何一直提示Dataset not in edit or insert mode.
- 我想在image上实现像股票一样鼠标跟随的十字线效果,请高手帮忙?
- 大家一起讨论一下,如何用对EXCEL的数据操作的结果进行分析。
- 再用200分来问一个问题, 大家给点意见.
- use xxunit除了用手工添加,有没有快捷的办法呢?
- 我是DELHI的初学者,有问题请大家帮忙,如果你有空的话,就回答我好吗?多谢!!
- 怎样把数据库里的1979-08-02转换为25岁啊?
- 这条简单的SQL语句为什么在ACCESS里查不出数据
和c中的union是一个意思那个integer其实没太多意思
To declare a record type with a variant part, use the following syntax.type recordTypeName = record fieldList1: type1;
...
fieldListn: typen;
case tag: ordinalType of
constantList1: (variant1);
...
constantListn: (variantn);
end;The first part of the declaration梪p to the reserved word case梚s the same as that of a standard record type. The remainder of the declaration梖rom case to the optional final semicolon梚s called the variant part. In the variant part,tag is optional and can be any valid identifier. If you omit tag, omit the colon (:) after it as well.
ordinalType denotes an ordinal type.
Each constantList is a constant denoting a value of type ordinalType, or a comma-delimited list of such constants. No value can be represented more than once in the combined constantLists.
Each variant is a comma-delimited list of declarations resembling the fieldList: type constructions in the main part of the record type. That is, a variant has the formfieldList1: type1; ...
fieldListn: typen;where each fieldList is a valid identifier or comma-delimited list of identifiers, each type denotes a type, and the final semicolon is optional. The types must not be long strings, dynamic arrays, variants (that is, Variant types), or interfaces, nor can they be structured types that contain long strings, dynamic arrays, variants, or interfaces; but they can be pointers to these types.Records with variant parts are complicated syntactically but deceptively simple semantically. The variant part of a record contains several variants which share the same space in memory. You can read or write to any field of any variant at any time; but if you write to a field in one variant and then to a field in another variant, you may be overwriting your own data. The tag, if there is one, functions as an extra field (of type ordinalType) in the non-variant part of the record.Variant parts have two purposes. First, suppose you want to create a record type that has fields for different kinds of data, but you know that you will never need to use all of the fields in a single record instance. For example,type TEmployee = record
FirstName, LastName: string[40];
BirthDate: TDate;
case Salaried: Boolean of
True: (AnnualSalary: Currency);
False: (HourlyWage: Currency);
end;The idea here is that every employee has either a salary or an hourly wage, but not both. So when you create an instance of TEmployee, there is no reason to allocate enough memory for both fields. In this case, the only difference between the variants is in the field names, but the fields could just as easily have been of different types. Consider some more complicated examples:type TPerson = record
FirstName, LastName: string[40];
BirthDate: TDate;
case Citizen: Boolean of
True: (Birthplace: string[40]);
False: (Country: string[20];
EntryPort: string[20];
EntryDate, ExitDate: TDate);
end;type TShapeList = (Rectangle, Triangle, Circle, Ellipse, Other);
TFigure = record
case TShapeList of
Rectangle: (Height, Width: Real);
Triangle: (Side1, Side2, Angle: Real);
Circle: (Radius: Real);
Ellipse, Other: ();
end;For each record instance, the compiler allocates enough memory to hold all the fields in the largest variant. The optional tag and the
constantLists (like Rectangle, Triangle, and so forth in the last example above) play no role in the way the compiler manages the fields; they are there only for the convenience of the programmer.
The second reason for variant parts is that they let you treat the same data as belonging to different types, even in cases where the compiler would not allow a typecast. For example, if you have a 64-bit Real as the first field in one variant and a 32-bit Integer as the first field in another, you can assign a value to the Real field and then read back the first 32 bits of it as the value of the Integer field (passing it, say, to a function that requires integer parameters).
用用就知道了。