TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;我查了说delphi中如果类成员不加权限说明就是private的  
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
没有加权限说明,应该是和在private中效果是一样的吧,可是我把它们剪贴到private中提示出错了,找不到这两个成员了。
我在图书馆随便借了本DELPHI的书,那书挺烂的,上面也没写。

解决方案 »

  1.   

    类默认的封装等级是public类型
      

  2.   

    要学会看帮助
    Visibility of class members
    [code]
    ...
    If a member's declaration appears without its own visibility specifier, the member has the same visibility as the one that precedes it. Members at the beginning of a class declaration that don't have a specified visibility are by default published, provided the class is compiled in the {$M+} state or is derived from a class compiled in the {$M+} state; otherwise, such members are public.
    ...
    [/code]VCL 控件类型离 TObject 最近的是 TPersistent,再注意 Classes 单元里它的声明:{$M+}  TPersistent = class(TObject)
      ...
      end;{$M-}由于 TForm1 继承自 TPersistent,后者的默认可见域是 published,所以 TForm1 的默认域也是 published
      

  3.   

    Visibility of class membersEvery member of a class has an attribute called visibility, which is indicated by one of the reserved words private, protected, public, published, or automated. For example,published property Color: TColor read GetColor write SetColor;declares a published property called Color. Visibility determines where and how a member can be accessed, with private representing the least accessibility, protected representing an intermediate level of accessibility, and public, published, and automated representing the greatest accessibility.Private, protected, and public membersPublished membersAutomated membersIf a member's declaration appears without its own visibility specifier, the member has the same visibility as the one that precedes it. Members at the beginning of a class declaration that don't have a specified visibility are by default published, provided the class is compiled in the {$M+} state or is derived from a class compiled in the {$M+} state; otherwise, such members are public.For readability, it is best to organize a class declaration by visibility, placing all the private members together, followed by all the protected members, and so forth. This way each visibility reserved word appears at most once and s the beginning of a new "section" of the declaration. So a typical class declaration should like this:type
      TMyClass = class(TControl)
      private
       ... { private declarations here}
      protected
       ... { protected declarations here }
      public
       ... { public declarations here }
      published
       ... { published declarations here }
      end;You can increase the visibility of a member in a descendant class by redeclaring it, but you cannot decrease its visibility. For example, a protected property can be made public in a descendant, but not private. Moreover, published members cannot become public in a descendant class. For more information, see Property overrides and redeclarations.
      

  4.   


     类默认的封装等级是  published Members at the beginning of a class declaration that don't have a specified visibility are by default published
      

  5.   

    默认的是published,published的内容是有RTTI属性的,在程序运行中,控件类的button要是published,因为DFM文件中有它的配置,运行时找不到就报错喽
      

  6.   

    都正解毛啊,csdn 用户连文档都看不懂么?默认是 public,VCL 控件因为继承自 TPersistent,所以才变成 published
      

  7.   

    嗯,说private的估计是被C++误导了。
    不过我个人不写不带访问声明的代码,为何不让代码清晰些?
      

  8.   

    断章取义
    Members at the beginning of a class declaration that don't have a specified visibility are by default published, provided the class is compiled in the {$M+} state or is derived from a class compiled in the {$M+} state
      

  9.   

    默认是private
    而加了{$M+}之后默认是Published.
    所以自TPersistent派生的都是Published.除非某个派生类加了{$M-}