.files/ico_printer.gif)
OO-related Skill Level:
02/21/2001 Search Keys:
delphi delphi3000 article Object Model OO interfaces Times Scored:
11 Visits:
Company: bluestep.com IT-Consulting Reference: Ray Lischner - O''''Reilly Question/Problem/Abstract:
Reprinted with permission from O''''Reilly & Associates
Delphi in a NutshellBy Ray Lischner
1st Edition March 2000
1-56592-659-5, Order Number: 6595
600 pages, $24.95
Get the book at amazon.com
Classes and Objects
Think of a class as a record on steroids. Like a record, a class describes a type that comprises any number of parts, called fields. Unlike a record, a class can also contain functions and procedures (called methods), and properties. A class can inherit from another class, in which case it inherits all the fields, methods, and properties of the ancestor class.
An object is a dynamic instance of a class. An object is always allocated dynamically, on the heap, so an object reference is like a pointer (but without the usual Pascal caret operator). When you assign an object reference to a variable, Delphi copies only the pointer, not the entire object. When your program finishes using an object, it must explicitly free the object. Delphi does not have any automatic garbage collection (but see the section "Interfaces," later in this chapter).
For the sake of brevity, the term object reference is often shortened to object, but in precise terms, the object is the chunk of memory where Delphi stores the values for all the object''''s fields. An object reference is a pointer to the object. The only way to use an object in Delphi is through an object reference. An object reference usually comes in the form of a variable, but it might also be a function or property that returns an object reference.
A class, too, is a distinct entity (as in Java, but unlike C ). Delphi''''s representation of a class is a read-only table of pointers to virtual methods and lots of information about the class. A class reference is a pointer to the table. (Chapter 3, Runtime Type Information, describes in depth the layout of the class tables.) The most common use for a class reference is to create objects or to test the type of an object reference, but you can use class references in many other situations, including passing class references as routine parameters or returning a class reference from a function. The type of a class reference is called a metaclass.
Example 2-1 shows several class declarations. A class declaration is a type declaration that starts with the keyword class. The class declaration contains field, method, and property declarations, ending with the end keyword. Each method declaration is like a forward declaration: you must implement the method in the same unit (except for abstract methods, which are discussed later in this chapter).
type
TAccount = class
private
fCustomer: string; // name of customer
fNumber: Cardinal; // account number
fBalance: Currency; // current account balance
end;
TSavingsAccount = class(TAccount)
private
fInterestRate: Integer; // annual percentage rate, scaled by 1000
end;
TCheckingAccount = class(TAccount)
private
fReturnChecks: Boolean;
end;
TCertificateOfDeposit = class(TSavingsAccount)
private
fTerm: Cardinal; // CD maturation term, in days
end;
var
CD1, CD2: TAccount;
begin
CD1 := TCertificateOfDeposit.Create;
CD2 := TCertificateOfDeposit.Create;
...
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!
相关文章
热点关注
- AnsiString?PChar?赋值
- Report Machine 3.0 (报表
- MapX v5.02.25 破解文件
- WDBOX v1.0 多选下拉列表
- 用Delphi开发视频聊天软件
- Delphi客户服务器应用开发
- AES 加密算法函数包及演示
- ACCESS/SQL 数据库存取图
- 熊猫烧香核心源码(Delphi
- 把整个网页保存成JPG图片(
- 高级计算器 V1.0 (含代码)
- Delphi版模仿熊猫烧香病毒
- 精确定位打印程序 (含源代
- Delphi文件管理(六)
- 将数字四舍五入保留两位小
- 绝地程序编辑器 v1.0.1.4
- 关于自定义界面的方案(Eas
- Delphi 对象链接与嵌入(
- 用HTML页面做程序界面演示
- Delphi模拟最小化恢复关闭
- 用Delphi实现24位真彩色图
- 限制客户机运行程序 (有关
- Delphi中用API实现在MSN的
- DELPHI数据库应用程序的开
- Delphi 动态链接库编程(
- QQ号码自动申请器及源代码
- Win9x 下调整系统时钟控件
- delphi中的XML解析控件TXM
- 几个游戏内存修改器代码
- TT8 DevExpress 最新系列
- Tnt Delphi Unicode Contr
- DelphiTwain 2004-1-20 (
- Delphi中数据的自动录入
- 经验技巧:分享两条Delphi
- Delphi中Hash表的使用方法
IDC资讯
虚拟主机
域名注册
托管租用
vps主机
智能建站
网站运营
建站经验
策划盈利
搜索优化
网站推广
免费资源
网站联盟
联盟新闻
联盟介绍
联盟点评
网赚技巧
行业资讯
业界动态
搜索引擎
网络游戏
门户动态
电子商务
广告传媒
网络编程
Asp.Net编程
Asp编程
Php编程
Xml编程
Access
Mssql
Mysql
其它
服务器技术
Web服务器
Ftp服务器
Mail服务器
Dns服务器
安全防护
软件技巧
其它软件
Word
Excel
Powerpoint
Ghost
Vista
QQ空间
QQ
FlashGet
迅雷
Internet Explorer
网页制作
FrontPages
Dreamweaver
Javascript
css
photoshop
fireworks
Flash
程序设计
Java技术
C/C++
VB
delphi
网络知识
网络协议
网络安全
网络管理
组网方案
Cisco技术
操作系统
Win2000
WinXP
Win2003
Mac OS
Linux
FreeBSD



