Originale-mail to me for new edition

 

Published members

 

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, 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.

 

Topic groups

 

See also

Enumerated types

Inheritance and scope

Private, protected, and public members

Visibility of class members

 

 

译文

 

公布成员

 

公布成员(published)和公共成员(public)具有相同的可见度。不同的是,运行时信息RTTIruntime type information)为公布成员产生。RTTI允许应用程序动态地查询对象的域和属性、定位对象的方法。RTTI用于在下列情形下访问属性的值:保存和加载文件时,在对象检查器(Object Inspector)中显示属性时,将指定的方法(即事件处理程序)与指定的属性(即事件)关联时。

公布属性只限于某些数据类型。序数、串、类、接口和方法指针等类型可以被公布;由此可见,提供的基类型其上下界范围的序数值在031之间的集合类型也可以被公布,即集合必需适合于字节、字或双字(ByteWordDouble Word);除Real48之外,任何实数类型都可以被公布。数组类型的属性(不同于下面述及的数组属性array properties)不能被公布。

一些属性,尽管可以公布,但不完全支持流系统。这些属性包括记录类型的属性,所有可公布类型的数组属性,以及包括匿名值的枚举类型的属性。如果公布了这些属性中的某一种,那么对象检查器(Object Inspector)不能正确显示其值,当对象以流的形式写入磁盘时也不能保存其值。

所有的方法都是可公布的,但一个类不能公布两个或更多重载的同名方法。域可以被公布,仅当该域是一个类类型或接口类型。

一个类不能拥有公布成员,除非该类在 {$M+} 状态下编译或者起源于在 {$M+} 状态下编译的类。大多数有公布成员的类起源于TPersistent类(VCLCLX中提供),该类在 {$M+} 状态下编译,因此很少有必要使用 {$M} 编译指示。

 

主题组

 

相关主题

枚举类型

继承和作用域

私有成员,保护成员和公共成员

类成员的可见度

 

 

编者注

公布属性和公共属性的区别在于前者用于运行时信息。从DelphiKylix的开发特性来说,公布属性为可视化开发提供了最基本的条件。大多数公布属性可以在设计时被读或写(对象检查器中还可以看到只读属性),所有的公布属性在运行时可以提供运行时信息。甚至在设计时编译器会调用一段相关代码而不必运行程序(例如,向一个整数属性填入浮点值时,编译器会调用该属性赋值方法中对异常的处理代码)。