有关CLASS的问题
如protected private publish 在他们下面声明、定义属性、方法、事件有什么不同啊!构造函数、析构函数的定义生命必须在公共标志下面吗? 问题点数:0、回复次数:6Top
1 楼bluemeteor(挂月||Becoder)回复于 2003-03-03 12:46:30 得分 0
找一本object pascal的入门书籍来阅读一下吧Top
2 楼huangrenguang(湖)回复于 2003-03-03 12:49:50 得分 0
建议去看看有关面向对象方面的书。Top
3 楼fancier(OP&&C/C++)回复于 2003-03-03 12:50:28 得分 0
//Delphi帮助
A private member is invisible outside of the unit or program where its class is declared. In other words, a private method cannot be called from another module, and a private field or property cannot be read or written to from another module. By placing related class declarations in the same module, you can give the classes access to one another抯 private members without making those members more widely accessible.
A protected member is visible anywhere in the module where its class is declared and from any descendant class, regardless of the module where the descendant class appears. In other words, a protected method can be called, and a protected field or property read or written to, from the definition of any method belonging to a class that descends from the one where the protected member is declared. Members that are intended for use only in the implementation of derived classes are usually protected.
A public member is visible wherever its class can be referenced.
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抰 display it correctly, nor will the property抯 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.
//构造函数、析构函数的定义生命必须在公共标志下面吗?
是的Top
4 楼netfyee(为了MM努力赚钱)回复于 2003-03-03 12:52:29 得分 0
protected保护的只有在子类等中访问
private私有的 只能在当前class或当前unit中访问
publish 是用于发布属性。用于在设计期在inspector中操作的
构造函数、析构函数的定义生命应该必须在公共标志下面。因为一般都在外部构造,析构 类的实例
Top
5 楼vitamin_ok(水水|Eddie(vitamin_ok@mail.csdn.net))回复于 2003-03-03 12:52:37 得分 0
去看看object pascal的书吧,你的问题,应该都有的!Top
6 楼findcsdn(searchcsdn)回复于 2003-03-03 12:56:40 得分 0
private 的成员只有自己可以访问.
protected 相同单元内的其他类和该类的子类可以访问.
public 其他类都可以访问。
构造函数和析构函数的定义因该必须public,因为程序中要用该函数创建实例,如果放在private下面,那么其他程序就看不到该函数,那么这个类就无法初始化,也不可以从该类扩展子类了。 多写写程序,这些概念就会分清了。Top




