1 / 20
文档名称:

Delphi面向对象编程 读书笔记.doc

格式:doc   页数:20
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

Delphi面向对象编程 读书笔记.doc

上传人:zbfc1172 2013/1/9 文件大小:0 KB

下载得到文件列表

Delphi面向对象编程 读书笔记.doc

文档介绍

文档介绍:Delphi面向对象编程读书笔记
<<Delphi面向对象编程>>读书笔记之一
<1> Delphi中类的声明语法如下:
 type 类名  = class(基类名)
  {数据成员声明}
  {过程和函数声明}
  {属性声明}
 end;
 Example:
 type
  TMan=class
  private
   FAge:Integer;
   procedure SetAge(Value:Integer);
  public
   Language:string;
   Married:Boolean;
   Name:string;
   SkinColor:string;
   constructor Create;overload;
   class procedure Sing;             //唱国歌
   property  Age:Integer read FAge write SetAge;
   procedure SayHello(words:string);
 end; 
  
<2> 对象构建
  Delphi中的类默认都是从TObject类继承而来,对象的创建必须调用构造函数
  Delphi中的对象分配存储空间都是在堆上,这点和C++不同,C++是可以在栈上分配对象的
  Example:
  procedure (Sender: TObject);
  var 
   APerson:TMan;
  begin
   APerson:=;
  end;
  ,因为Create前面有constructor 关键字
  constructor 相当于将Create声明为Class方法[相当于C++中 static方法]
  
<3> 刘老师在书上的解释如下
  原话如下啊:"注意这里的调用构造函数的语法有点特殊,是通过类型来引用一个对象的Create方法,而不是象其他
  ,但很有意义,变量APerson在调用时还没有定义,而类TMan已经静态地存在
  于内存中,静态方法调用它的Create方法是合法的"
  "而类TMyObject已经静态地存在于内存中"我本人对这句话有点疑惑,类是不占存储空间的,怎么可以说类TMyObject已经静态地存在于内存中呢?
  我将在后面给出我的想法,暂时就到此
  
<4> 关于is与as
  这两个都是运行期判别对象所属类型的操作符
  两则的用法的语法上相似: 对象变量 is /as 类名
  给出书上的例子说明问题
  procedure (sender,source:TObject;x,y:Integer)
  begin
   if Source is TEdit then
    
((Source as TEdit).Text);
  end;
<5>关于self
  在普通方法中self变量的值是对象的应用,而在类方法中,self变量的值是类引用
  Example:
  TMan=class
  private
   FAge:Integer;
   procedure SetAge(Value:Integer);
  public
   Language:string;
   Married:Boolean;
   Name:string;
   SkinColor:string;
   constructor Create;overload;
     class procedure Sing;             //唱国歌
   procedure SayHello(words:string); //打招呼
     property  Age:Integer read FAge write SetAge;
  end;
 
  constructor ;
  begin
  &#