Marco Cantù
Object Pascal Handbook
The Complete Guide to the Object Pascal programming
language for Delphi and AppMethod developers
Piacenza (Italy), July 2015
Author: Marco Cantù
Publisher: Marco Cantù
Editor: Peter W A Wood
Cover Designer: Fabrizio Schiavi (www.fsd.it)
Copyright 1995-2015 Marco Cantù, Piacenza, Italy. World
rights reserved.
The author created example code in this publication expressly for the free use by its
readers. Source code for this book is copyrighted freeware, distributed via the web
site http://code.marcocantu.com. The copy- right prevents you from
republishing the code in print or electronic media without permission. Readers are
granted limited permission to use this code in their applications, as long at the code
itself is not distributed, sold, or commercially exploited as a stand-alone product.
Aside from this specific exception concerning source code, no part of this publication
may be stored in a retrieval system, transmitted, or reproduced in any way, in the
original or in a translated language, including but not limited to photocopy,
photograph, magnetic, or other record, without the prior agreement and writ- ten
permission of the publisher.
Delphi and Appmethod are trademarks of Embarcadero Technologies. Other
trademarks are of the respective owners, as referenced in the text. Whilst the author
and publisher have made their best efforts to prepare this book, they make no
representation or warranties of any kind with regard to the completeness or accuracy
of the contents herein and accepts no liability of any kind including but not limited to
performance, mer- chantability, fitness for any particular purpose, or any losses or
damages of any kind caused or alleged to be caused directly or indirectly from this
book.
Object Pascal Handbook
ISBN-10: 1514349949
ISBN-13: 978-1514349946
The electronic edition of this book has been licensed to Embarcadero
Technologies Inc and it is also sold directly by the author. Any other download
or sale outlet is likely to be illegal. Do not distribute the PDF version of this
book without permission. The printed edition is self-published through
CreateSpace Inc and sold in several online outlets.
More information on
http://www.marcocantu.com/objectpasca l
1
begin
功能强大且简单、容易表达又具可读性、初学者跟专业人员都能快速熟悉,
这些就是今日 Object Pascal 的部份特点。
Object Pascal 历久弥新,不断向前演进,而演进至今,更具备了多种不同面
向,它结合了面向对象程序语言的强大、泛型程序的高阶功能,以及动态
结构特性 (anonymous function 等结构化的程序区块),却也没有舍弃许多程
序化语言的传统特性。Object Pascal 适合所有行业,是一个在行动时代具备
编译功能的开发工具,更是一个具备坚强历史,已经准备好面对未来挑战
的程序语言。
Object Pascal 是为了开发什么特定功能而存在的? 从单机桌面到主从式架
构应用程序,从大量处理数据的 web 模块到中间件,从办公室自动化到最
新的行动装置(手机与平板 app)的开发,从工厂自动化系统到网际/移动电话
虚拟网络等等,这些都不是这个语言被设计准备来处理的领域,而是在今
日世界中,Object Pascal 这个语言已经实际在服务的领域,这就是 Object
Pascal 强大的地方,它不是预期可以做这些事,而是已经做到了。
我们今日使用的 Object Pascal 程序语言的核心,都是早在 1995 年,那个程
序语言发展的黄金年代就已经定义好的,在同一个年代,JAVA跟 JAVAScript
也刚被开发出来。虽然 Object Pascal 语言的根基是在那么久以前就已经奠
定的,而且还有更久以前的 Pascal 语言,这个程序语言的发展并没有在 1995
年停下脚步,直至今日,它的核心功能仍旧不断的在增强当中,我们可以
在 Embarcadero 的 Appmethod, Delphi跟 RAD Studio 当中这些功能在单机应
用程序与行动应用程序、编译程序与开发工具的领域中继续进步着。
一本介绍现代程序语言的书
随着程序语言的角色不断变化,功能的延伸也逐年在发生,最终会反应在
程序语言会吸引新的开发人员。我觉得写一本能够完整介绍现代的 Object
Pascal 所涵盖的各个领域是很重要的。这个目标是要让新进的开发人员能够
有语言的手册,让对其他相似语言熟悉的开发人员也能快速入门,也让在
2
过去的这些年里,对熟悉不同版本 Pascal 的开发人员能快速的知道目前
Object Pascal 究竟有了什么发展。
新进的开发人员当然需要一些基础,但在刚开始的章节中,即使是熟悉过
去不同版本 Object Pascal 的开发人员,一定也能得到一些新的心得。我们
会以一个篇幅不长的附录来简单介绍 Object Pascal 语言的历史,其余的篇
幅则会着重在今日的 Object Pascal。
从早期的 Delphi 开始,大多数的核心功能并没有很显著的变化,绝大多数
很重要的核心功能,早在 1995 年第一版的 Delphi 当中就已经奠定了基础。
在我即将开始介绍的本书的内容当中,这个程序语言在这么多年的存在过
程中,并不是停滞不前的,它在过去的这段期间中,以相当快的速度在进
化着。
在我过去其他的作品当中,我的介绍手法比较传统,首先会介绍最传统的
Pascal 程序语言,接着或多或少介绍一些在发展过程中被加入的延伸功能。
但在这本书里,我会直接切中主题,直接介绍今日我们怎么透过 Object
Pascal 解决问题,或者怎么用它最好,而不会介绍它一路走来是怎么演进的
了。
举例来说,最近被提出的原生的数据型别具备面向对象特性中 method 的功
能,可溯及原始 Pascal 语言。这部份我在第二章里面就会直接介绍怎么使
用这个功能,而不会试图先让读者们理解这当中的设计运作原理。
换句话说,这本书会着重在让读者们怎么在今时今日使用 Object Pascal,从
基础引导、让读者们从做中学,只会提到最低限度的历史发展。即使读者
们已经很熟悉这个语言了,应该还是会希望直接切入主题,至于历史的发
展与脉络,我们只在最后一章介绍。
从做中学
这本书的意旨,是要介绍核心概念,并透过很短的范例让读者立即进入状
况,透过这些范例,读者们可以试着执行、练习、并且自行摸索了解到概
念,并对这些概念有更深切的体认。
这本书不会是一本参考手册,参考手册会解释这个程序语言在理论上该怎
么做,并列举所有可能的案例作为说明。而为了精确的介绍概念,本书会