DELPHI设置枚举类型size
delphi枚举类型长度默认为2个字节(单字),而在C中枚举为4个字节(双字),如果需要跨这两个平台编程,传输结构时会由于数据长度不一造成灾难。
经过查找资料,原来delphi可以通过{$Z+} {$Z-} {$Z1} {$Z4} 等宏设置枚举类型的长度,小至1个字节,大至4个字节。
官方说明如下:
The $Z directive controls the minimum storage size of Delphi enumerated types.
An enumerated type is stored as an unsigned byte if the enumeration has no more than 256 values, and if the type was declared in the {$Z1} state (the default). If an enumerated type has more than 256 values, or if the type was declared in the {$Z2} state, it is stored as an unsigned word. Finally, if an enumerated type is declared in the {$Z4} state, it is stored as an unsigned double word.
The {$Z2} and {$Z4} states are useful for interfacing with C and C++ libraries, which usually represent enumerated types as words or double words.
Note: Note: For backwards compatibility with early versions of Delphi and CodeGear Pascal, the directives {$Z-} and {$Z+} are also supported. They correspond to {$Z1} and {$Z4}, respectively.
例子如下:
http://www.delphibasics.co.uk/RTL.asp?Name=$Z
Example code : Various enum type sizes
type
{$Z1}
TCars1 = (Rover, Jaguar, Honda); // Will fit into 1 byte
TFruit1 = (Banana=255, Apple, Pear); // Will exceed one byte
{$Z4}
TCars2 = (Ford, Nissan, Vauxhall); // Now uses 4 bytes
TFruit2 = (Orange=255, Plum, Grape); // Now uses 4 bytes
begin
ShowMessage('TCars1 size = '+IntToStr(SizeOf(TCars1)));
ShowMessage('TFruit1 size = '+IntToStr(SizeOf(TFruit1)));
ShowMessage('TCars2 size = '+IntToStr(SizeOf(TCars2)));
ShowMessage('TFruit2 size = '+IntToStr(SizeOf(TFruit2)));
end;
TCars1 size = 1
TFruit1 size = 2
TCars2 size = 4
TFruit2 size = 4
DELPHI设置枚举类型size的更多相关文章
- DELPHI中枚举类型数据的介绍和使用方法
在看delphi程序的时候看到aa=(a,b,c,d);这样的东西,还以为是数组,同事说是函数,呵呵,当然这两个都不屑一击,原来这样式子是在声明并付值一个枚举类型的数据.下边写下来DELPHI中枚举类 ...
- Delphi的枚举类型
参考:http://blog.csdn.net/kissdeath/article/details/2060573 Delphi程序不仅可以用于数值处理,还更广泛的用于处理非数值的数据.例如:性别.月 ...
- delphi 枚举类型
枚举类型定义了一系列有序值的集合.枚举变量就是从这个既定的集合中取某个值.集合中的有序值可以称为元素,元素一般从0开始索引(也就是元素的顺序号). 定义一个枚举类型,采用以下的格式: type typ ...
- 【转】Android中的内存管理--不错不错,避免使用枚举类型
原文网址:http://android-performance.com/android/2014/02/17/android-manage-memory.html 本文内容翻译自:http://dev ...
- C# 获取与解析枚举类型的 DescriptionAttribute
原文:C# 获取与解析枚举类型的 DescriptionAttribute System.ComponentModel.DescriptionAttribute 这个 Attribute,经常被用来为 ...
- { MySQL基础数据类型}一 介绍 二 数值类型 三 日期类型 四 字符串类型 五 枚举类型与集合类型
MySQL基础数据类型 阅读目录 一 介绍 二 数值类型 三 日期类型 四 字符串类型 五 枚举类型与集合类型 一 介绍 存储引擎决定了表的类型,而表内存放的数据也要有不同的类型,每种数据类型都有自己 ...
- golang枚举类型 - iota用法拾遗
在c#.java等高级语言中,经常会用到枚举类型来表示状态等.在golang中并没有枚举类型,如何实现枚举呢?首先从枚举的概念入手. 1.枚举类型定义 从百度百科查询解释如下:http://baike ...
- 在WPF中使用变通方法实现枚举类型的XAML绑定
问题缘起 WPF的分层结构为编程带来了极大便利,XAML绑定是其最主要的特征.在使用绑定的过程中,大家都普遍的发现枚举成员的绑定是个问题.一般来说,枚举绑定多出现于与ComboBox配合的情况,此时我 ...
- TypeScript中的枚举类型
TypeScript拓展了Javascript原生的标准数据类型集,增加了枚举类型(enmu)和其他语言一 样 它提供我们一种数字类型的值,用来设置由于辨别的名字和方法 enum Students { ...
随机推荐
- [poj3666]Making the Grade(DP/左偏树)
题目大意:给你一个序列a[1....n],让你求一个序列b[1....n],满足 bi =a && bc,则最小的调整可以是把b变成c. 所以归纳可知上面结论成立. dp[i][j] ...
- 用CSS做长度超过长度显示‘...’,当鼠标放上时显示全部内容
<!DOCTYPE html> <html> <head> <meta name="author" content="Yeeku ...
- 解决系统打开CHM文件无法正常显示
最近学习servlet下载了一个CHM的帮助手册但是打开后右侧却时空白.试了各种方法都没有成功最后终于找到原因所在. 一般情况下无法显示网页:右键 chm文件属性里最下面有个“解除锁定”,点击“解除锁 ...
- java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStreamsJavamail问题
异常描述如下: Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/LineI ...
- usefull-url
http://www.johnlewis.com/ http://codepen.io/francoislesenne/pen/aIuko http://www.rand.org/site_info/ ...
- 大概了解了flexbox
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- 关于 Maven 的插件maven-war-plugin
在进行项目发布的时候,可能会碰到这样的情况, 希望在保持项目源代码不变的前提下,希望能够针对不同的运行环境获得相应的运行包.(比如war包) 基本配置 :(包括排除 不想打进war包的jar 的配置) ...
- Html-Css-设置DIV边框圆滑
border-radius: 10px; -moz-border-radius: 10px; -webkit-border-radius: 10px; -o-border-radius: 10px; ...
- 替换文件最后一行中的所有e 为 E
#root@athena5plus:~# cat b northwest NW Charles Main 3.0 .98 3 ...
- jquery插件库
jQuery由美国人John Resig创建,至今已吸引了来自世界各地的众多javascript高手加入其team. jQuery是继prototype之后又一个优秀的Javascrīpt框架.其经典 ...