unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

//类声明
  TMyClass = class
  public
    class procedure MyProc;  //类方式
    constructor Create;      //Create 也是类方法
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TMyClass }

constructor TMyClass.Create;
begin
  inherited;
  MyProc;  //内部调用类方法
end;

class procedure TMyClass.MyProc;
begin
  ShowMessage('ok');  //类方法实现
end;


procedure TForm1.FormCreate(Sender: TObject);
var
  MyClass1: TMyClass;
begin
  TMyClass.MyProc;  //用类名调用类方法,显示:ok
  MyClass1 := TMyClass.Create;  //内部调用类方法,显示:ok
  MyClass1.MyProc;  //对象调用类方法,显示:ok
  MyClass1.Free;
end;

end.
posted on 2007-12-05 14:05  万一  阅读(6527)  评论(9编辑  收藏  举报