VB6中Property Set和Property Let有什么区别?
我刚刚创建了几个 Property Set
方法,但它们未编译。当我将它们更改为 Property Let
时,一切都很好。
此后,我研究了文档以找出 Property Set
和 Property Let
之间的区别,但必须承认我一点也不明智。有什么区别吗?如果有的话有人可以提供一个正确解释的指针吗?
I have just created several Property Set
methods, and they didn't compile. When I changed them to Property Let
, everything was fine.
I have since studied the documentation to find the difference between Property Set
and Property Let
, but must admit to being none the wiser. Is there any difference, and if so could someone offer a pointer to a proper explanation of it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Property Set
用于对象(例如,类实例)Property Let
用于“普通”数据类型(例如,字符串、布尔值、长整型等)Property Set
is for objects (e.g., class instances)Property Let
is for "normal" datatypes (e.g., string, boolean, long, etc.)Property Let
比Property Set
更通用。后者仅限于对象引用。如果您在类中具有此属性,您可以使用
Property Set Picture
调用您可以使用两者调用
Property Let Picture
实现
Property Set
是什么开发人员期望属性是对象引用,但有时甚至 Microsoft 也只为引用属性提供Property Let
,从而导致不带Set< 的不寻常语法
oObj.Object = MyObject
/代码> 声明。在这种情况下,使用Set
语句会导致编译时或运行时错误,因为oObj
类上没有实现Property Set Object
。我倾向于为标准类型(字体、图片等)的属性实现
Property Set
和Property Let
,但具有不同的语义。通常在Property Let
上,我倾向于执行“深度复制”,即克隆StdFont
而不是仅仅保存对原始对象的引用。Property Let
is more versatile thanProperty Set
. The latter is restricted to object references only. If you have this property in a classYou can call
Property Set Picture
withYou can call
Property Let Picture
with bothImplementing
Property Set
is what other developers expect for properties that are object references but sometimes even Microsoft provide onlyProperty Let
for reference properties, leading to the unusual syntaxoObj.Object = MyObject
withoutSet
statement. In this case usingSet
statement leads to compile-time or run-time error because there is noProperty Set Object
implemented onoObj
class.I tend to implement both
Property Set
andProperty Let
for properties of standard types -- fonts, pictures, etc -- but with different semantics. Usually onProperty Let
I tend to perform "deep copy", i.e. cloning theStdFont
instead of just holding a reference to the original object.Property Set
用于类对象变量 (ByRef),而Property Let
用于类值变量 (ByVal)Property Set
is for object-like variables (ByRef) whereasProperty Let
is for value-like variables (ByVal)