张志峰的博客

水滴石川,积少成多。

导航

Delphi 类方法也分私有和公有方法之分

Posted on 2011-08-31 17:00  ╰★张志峰★╮  阅读(670)  评论(0编辑  收藏  举报

类方法也分私有和公有方法之分,下面是具体代码

unit Unit2;

interface
uses
  Windows, Forms, Dialogs;

type
  TA = class
    private
      class procedure aa;

    public
      class procedure bb;

  end;


implementation

class procedure TA.aa;
begin
  showmessage('aa');
end;

class procedure TA.bb;
begin
  showmessage('bb');
end;

 

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
//
  TA.bb;  //编译通过
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  TA.aa;//编译通不过
end;

end.