linux社区爱心援助Linux认证系列教程业界动态站务新闻公司招聘建议留言网址大全LPI专题CISCO专题
设为首页
加入收藏
管理团队
JSP  
JAVA  
PERL  
 您的位置:首页 > 开发语言 > Delphi >
栏目导栏
  php
  JSP
  ASP
  asp.net
  JAVA
  c/c++/c#
  perl
  JavaScript
  Basic
  Delphi
资料搜索
热门文章
·HexToStr函数和StrToHex函数
·Delphi中的进制转换
·delphi轻松设置无边框透明窗体
·DELPHI组件安装全攻略
·delphi第三方控件安装(Ehlib)
·delphi动态创建控件
·开发工具比较Visual C++ VS De
·delphi完整身份证效验程序实例
·如何判断文本文件的编码格式
·深入研究Variant数组
·delphi中的Format函数详解
·用delphi编写网络游戏的外挂
·Delphi技巧-用户自定义数据类型
·delphi编程获取打印机的打印任
·delphi设置控件透明
最新文章
·在应用程序中跟踪MOUSE的坐标
·压缩和修复MS Access 2000文件
·DELPHI 6.0 动画制做
·怎样在Delphi中调用LastError信
·怎样得到主域服务器名称
·怎样利用递归实现删除某一目录
·读出主键下所有项
·如何制作照片底片效果的图像(
·获得Modem的状态
·WebBrowser屏幕滚动的实现,设
·有关字符串处理的小技巧
·Delphi建立键盘鼠标动作纪录与
·Delphi中布尔类型辨析
·DELPHI程序注册码设计
·图形的不规则的Copy
Google
 
Delphi中布尔类型辨析
[ 作者:  加入时间:2007-12-13 12:52:03  来自:Linux联盟收集整理 ]
Delphi中预定义的布尔类型有四种:Boolean ,ByteBool,WordBool,LongBool。其中,Boolean 类型是首选布尔类型,其余三种是为其它编程语言和Windows 环境提供兼容性支持。这些布尔类型在使用上大同小异,但如果混淆使用将可能会有意外结果。 cRSLinux联盟
cRSLinux联盟
  现做简单辨析供大家参考。 cRSLinux联盟
cRSLinux联盟
   cRSLinux联盟
cRSLinux联盟
  一、从资源占用的角度进行比较cRSLinux联盟
cRSLinux联盟
  一项Boolean 类型的数据占用 1字节的内存; cRSLinux联盟
cRSLinux联盟
  一项ByteBool类型的数据占用 1字节的内存; cRSLinux联盟
cRSLinux联盟
  一项WordBool类型的数据占用 2字节的内存; cRSLinux联盟
cRSLinux联盟
  一项LongBool类型的数据占用 4字节的内存。 cRSLinux联盟
cRSLinux联盟
  如果开发者在进行程序设计时将构造一种含有布尔数据类型的结构类型,那么在资源占用方面将有所考虑。尽管这些数据类型之间是可以相互赋值的,但某些特殊情况下是有区别的。首先看下面的语句: cRSLinux联盟
cRSLinux联盟
  type cRSLinux联盟
cRSLinux联盟
   ByteBoolFile = file of ByteBool; cRSLinux联盟
cRSLinux联盟
   LongBoolFile = file of LongBool; cRSLinux联盟
cRSLinux联盟
  这里,如果在这两中类型文件中存储相同数量的布尔值,其文件大小是不同的。而对同一物理文件按照这两种类型文件分别读取数据,其结果更是相去甚远。 cRSLinux联盟
cRSLinux联盟
  下面是比较ByteBool和LongBool的一段程序,得到的文件 test1.bin和 test2.bin的文件尺寸分别为 4字节和16字节。 cRSLinux联盟
cRSLinux联盟
  procedure CompareByteBoolWithLongBool; cRSLinux联盟
cRSLinux联盟
  const cRSLinux联盟
cRSLinux联盟
   FName1 = 'c: est1.bin'; cRSLinux联盟
cRSLinux联盟
   FName2 = 'c: est2.bin'; cRSLinux联盟
cRSLinux联盟
  type cRSLinux联盟
cRSLinux联盟
   ByteBoolFile = file of ByteBool; cRSLinux联盟
cRSLinux联盟
   LongBoolFile = file of LongBool; cRSLinux联盟
cRSLinux联盟
  var cRSLinux联盟
cRSLinux联盟
   BF: ByteBoolFile; cRSLinux联盟
cRSLinux联盟
   LF: LongBoolFile; cRSLinux联盟
cRSLinux联盟
   B: Boolean; cRSLinux联盟
cRSLinux联盟
  begin cRSLinux联盟
cRSLinux联盟
   B := False; cRSLinux联盟
cRSLinux联盟
   AssignFile(BF, FName1); cRSLinux联盟
cRSLinux联盟
   Rewrite(BF); cRSLinux联盟
cRSLinux联盟
   Write(BF, B, B, B, B); cRSLinux联盟
cRSLinux联盟
   CloseFile(BF); cRSLinux联盟
cRSLinux联盟
   AssignFile(LF, FName2); cRSLinux联盟
cRSLinux联盟
   Rewrite(LF); cRSLinux联盟
cRSLinux联盟
   Write(LF, B, B, B, B); cRSLinux联盟
cRSLinux联盟
   CloseFile(LF); cRSLinux联盟
cRSLinux联盟
  end; cRSLinux联盟
cRSLinux联盟
  有兴趣的朋友可以在此基础上再比较一下读取数据的区别,你会有更奇特的发现。cRSLinux联盟
Linux联盟收集整理 ,转贴请标明原始链接,如有任何疑问欢迎来本站Linux论坛讨论
评论】【加入收藏夹】【 】【打印】【关闭
※ 相关链接
 ·DELPHI程序注册码设计  (2007-12-13 12:51:16)
 ·在DELPHI中利用API实现网格内组件的嵌入  (2007-12-13 12:47:17)
 ·用Delphi打造图形界面的Ping程序  (2007-12-03 14:55:11)
 ·Delphi中异常的处理  (2007-12-03 14:50:54)
 ·在Delphi中侦测剪贴板的变化  (2007-12-03 14:48:21)
 ·delphi中的快捷键大收集  (2007-12-03 14:44:45)
 ·如何为Delphi程序添加事件和事件处理器  (2007-12-03 14:44:11)
 ·DELPHI中线程的初步探索  (2007-12-03 14:43:37)
 ·delphi端口扫描  (2007-12-03 14:39:06)
 ·DELPHI 中的规则表达式  (2007-12-03 14:37:59)