博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

类和对象

Posted on 2009-06-19 12:08  longker的博客  阅读(153)  评论(0)    收藏  举报

1.类的声明,格式:

Type
  TMyClass 
= class
end;

Type
  TBase 
= class
  
procedure msg1;
end;

Type
  TChild 
= class(TBase) //类的继承
  
procedure msg2;
end;

类可以声明在接口部分,也可以声明在应用部分;Type 只要一个联合使用就行,其他可以省略;

unit unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

Type
  TForm1 
= class(TForm)
end;

Type
  Tbase 
= class   //定义类
  b  :  TDate;    
//声明类的变量
  
procedure msg1; //类的方法
end;

var
  Form1 : TForm1;

implementation

procedure TBase.msg1; //定义过程实体
begin
  showmessage(
'Is Base');
end;

procedure TForm1.Button1Click(Sender : TOBJect);
var
  base : TBase;  
//声明类的变量,也就是类的对象;
begin
  base :
= TBase.Create; //类需要实例化才能使用;
  base.msg1;
  base.Free;     
//用完后释放;
end;
end.