我是一名新手,发现在声明一个类时有些属性时private,有些时public,还有些时published,不知道这个published是什么东东阿!

解决方案 »

  1.   

    delphi帮助中的很详细的说明,简单的英文,自己去看吧Published members have the same visibility as public members. The difference is that runtime type information (RTTI) is generated for published members. RTTI allows an application to query the fields and properties of an object dynamically and to locate its methods. RTTI is used to access the values of properties when saving and loading form files, to display properties in the Object Inspector, and to associate specific methods (called event handlers) with specific properties (called events).Published properties are restricted to certain data types. Ordinal, string, class, interface, variant, and method-pointer types can be published. So can set types, provided the upper and lower bounds of the base type have ordinal values between 0 and 31. (In other words, the set must fit in a byte, word, or double word.) Any real type except Real48 can be published. Properties of an array type (as distinct from 
    array properties, discussed below) cannot be published.Some properties, although publishable, are not fully supported by the streaming system. These include properties of record types, array properties of all publishable types, and properties of enumerated types that include anonymous values. If you publish a property of this kind, the Object Inspector won't display it correctly, nor will the property's value be preserved when objects are streamed to disk.All methods are publishable, but a class cannot publish two or more overloaded methods with the same name. Fields can be published only if they are of a class or interface type.A class cannot have published members unless it is compiled in the {$M+} state or descends from a class compiled in the {$M+} state. Most classes with published members derive from TPersistent, which is compiled in the {$M+} state, so it is seldom necessary to use the $M directive.
      

  2.   

    公布成员
     公布成员(published)和公共成员(public)具有相同的可见度。不同的是,运行时信息RTTI(runtime type information)为公布成员产生。RTTI允许应用程序动态地查询对象的域和属性、定位对象的方法。RTTI用于在下列情形下访问属性的值:保存和加载文件时,在对象检查器(Object Inspector)中显示属性时,将指定的方法(即事件处理程序)与指定的属性(即事件)关联时。公布属性只限于某些数据类型。序数、串、类、接口和方法指针等类型可以被公布;由此可见,提供的基类型其上下界范围的序数值在0到31之间的集合类型也可以被公布,即集合必需适合于字节、字或双字(Byte,Word或Double Word);除Real48之外,任何实数类型都可以被公布。数组类型的属性(不同于下面述及的数组属性array properties)不能被公布。一些属性,尽管可以公布,但不完全支持流系统。这些属性包括记录类型的属性,所有可公布类型的数组属性,以及包括匿名值的枚举类型的属性。如果公布了这些属性中的某一种,那么对象检查器(Object Inspector)不能正确显示其值,当对象以流的形式写入磁盘时也不能保存其值。所有的方法都是可公布的,但一个类不能公布两个或更多重载的同名方法。域可以被公布,仅当该域是一个类类型或接口类型。一个类不能拥有公布成员,除非该类在 {$M+} 状态下编译或者起源于在 {$M+} 状态下编译的类。大多数有公布成员的类起源于TPersistent类(VCL和CLX中提供),该类在 {$M+} 状态下编译,因此很少有必要使用 {$M} 编译指示。 
      

  3.   

    靠!复制那么多东西,别人看得懂还要来问啊???!!!
    private,public,published,protected
    我来简单说说:
    private:私有数据,只有本类和本单元可以访问其中的字段或是方法
    public:公有数据,只要引用的单元都可以访问其中的字段或是方法
    protected:保护数据,只有本类和他的子类可以访问其中的字段和方法
    published:属性,一种相当于public范围数据说明,只有字段(可以指向一个
               方法指针),只要引用的单元都可以访问。在Delphi中还表示为
               其中的字段成员将出现在Object Inspcetor(对象面板)中。
      

  4.   

    你应该选学习以下C++,重要的C++的思想。
    强烈的建议,因为你连这个都不懂,我相信你对类、OOP也一定懂得不多。
    如果这个都不懂那你以后学习Delphi就会更加困难了。
      

  5.   

    大部分是用在控件的编写上,但是也可以用与一般的程序设计,
    property text :String read Ftext write Ftext;