任何对象都可以添加属性!知道什么叫属性、属性的内部实现机制,对这个问题根本不需要有疑问——属性在语言内部就是一个方法,懂Java或C#之类的都明白。何况我多次示范过给各种控件添加属性的实例,包括最近那次。
[ 本帖最后由 TonyDeng 于 2014-9-15 20:18 编辑 ]
[ 本帖最后由 TonyDeng 于 2014-9-15 20:18 编辑 ]
授人以渔,不授人以鱼。
*--------------------------- * 住户信息显示控件 *--------------------------- DEFINE CLASS C_Household AS Container BorderWidth = 2 SpecialEffect = 0 _FontName = "微软雅黑" PROCEDURE _FontName_Assign(tcValue) IF VARTYPE(tcValue) != "C" tcValue = "微软雅黑" ENDIF WITH This ._FontName = tcValue .SetAll("FontName", ._FontName) ENDWITH ENDPROC _FontSize = 9 PROCEDURE _FontSize_Assign(tnValue) IF (VARTYPE(tnValue) != "N") .OR. (tnValue < 9) tnValue = 9 ENDIF WITH This ._FontSize = tnValue .Arrange ENDWITH ENDPROC _Width = 80 PROCEDURE _Width_Assign(tnValue) IF (VARTYPE(tnValue) != "N") .OR. (tnValue < 80) tnValue = 80 ENDIF WITH This ._Width = tnValue .Arrange ENDWITH ENDPROC _Height = 16 PROCEDURE _Height_Assign(tnValue) IF (VARTYPE(tnValue) != "N") .OR. (tnValue < 16) tnValue = 16 ENDIF WITH This ._Height = tnValue .Arrange ENDWITH ENDPROC * 房号 _Number = "" PROCEDURE _Number_Assign(tcValue) IF VARTYPE(tcValue) != "C" tcValue = "" ENDIF WITH This ._Number = tcValue .lbl_HouseNumber.Caption = ._Number ENDWITH ENDPROC * 户主名 _Name = "" PROCEDURE _Name_Assign(tcValue) IF VARTYPE(tcValue) != "C" tcValue = "" ENDIF WITH This ._Name = tcValue .lbl_HouseName.Caption = ._Name ENDWITH ENDPROC HIDDEN _Margin _Margin = 4 ADD OBJECT PROTECTED lbl_Title1 AS Label WITH Caption = "房号: ", Alignment = 1, Width = 50, Height = This._Height ADD OBJECT PROTECTED lbl_HouseNumber AS Label WITH Caption = This._Number, Alignment = 2, Width = This._Width, Height = This._Height ADD OBJECT PROTECTED lbl_Title2 AS Label WITH Caption = "户主: ", Alignment = 1, Width = 50, Height = This._Height ADD OBJECT PROTECTED lbl_HouseName AS Label WITH Caption = This._Name, Alignment = 2, Width = This._Width, Height = This._Height PROCEDURE Arrange WITH This .SetAll("FontSize", ._FontSize) .SetAll("BackStyle", 0) WITH .lbl_Title1 .Height = This._Height .Top = This._Margin .Left = This._Margin ENDWITH WITH This.lbl_HouseNumber .Width = This._Width .Height = This._Height .Top = This.lbl_Title1.Top .Left = This.lbl_Title1.Left + This.lbl_Title1.Width ENDWITH WITH This.lbl_Title2 .Height = This._Height .Top = This.lbl_Title1.Top + This.lbl_Title1.Height + This._Margin .Left = This._Margin ENDWITH WITH This.lbl_HouseName .Width = This._Width .Height = This._Height .Top = This.lbl_Title2.Top .Left = This.lbl_Title2.Left + This.lbl_Title1.Width ENDWITH .Width = .lbl_HouseNumber.Left + .lbl_HouseNumber.Width + ._Margin .Height = .lbl_HouseName.Top + .lbl_HouseName.Height + ._Margin ENDWITH ENDPROC PROCEDURE Resize This.Arrange ENDPROC ENDDEFINE
* 户主名 _Name = "" PROCEDURE _Name_Assign(tcValue) IF VARTYPE(tcValue) != "C" tcValue = "" ENDIF WITH This ._Name = tcValue .lbl_HouseName.Caption = ._Name ENDWITH ENDPROC