Delphi'private'子句(指令)不起作用

Yev*_*yev 1 delphi private class object

我正在尝试检查我的私人程序是否真的是私密的.但它的工作方式不应该如此.

请帮助我,也许我错过了关于封装应该如何工作的事情.

此代码不起作用.我猜.但它的确有效.

unit Unit1;

interface

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

type
    tmyclass = class
    private
      procedure one;
    end;

  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure tmyclass.one;
begin
  ShowMessage('1');
end;

procedure TForm1.Button1Click(Sender: TObject);
var myclass:tmyclass;
begin
  myclass.one;
end;

end.
Run Code Online (Sandbox Code Playgroud)

谢谢.(Delphi-7,Win7 x64).

Whi*_*ler 9

private是为了unit.

使用最新版本的Delphi,您可以使用它strict private来获得预期的行为.

  • 是的,这是正常行为.在同一单元中声明的类是彼此的隐式朋友,因此他们可以访问彼此的"protected"和"private"成员.在Delphi 8中引入了`strict protected`和`strict private`来避免隐含的友谊.但是,在Delphi 7中还没有"strict". (7认同)