类和对象

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.

 

posted @ 2014-12-16 20:39  delphiclub  阅读(160)  评论(0编辑  收藏  举报