Revision history for KeyPgVisProtected


Revision [22587]

Last edited on 2019-02-26 09:12:28 by fxm [Suppressed reference to fbc version 0.24]
Deletions:
NOTE: This keyword is useful only since fbc version 0.24 because inheritance is then supported.


Revision [21494]

Edited on 2016-05-22 03:50:52 by fxm [Added an example of protected member procedures (constructors and set-property)]
Additions:
{{fbdoc item="filename" value="examples/manual/udt/protected2.bas"}}%%(freebasic)
' Example to illustrate the access control 'Protected' with a token provided by an admin right for an user right:
' - The 'admin_right' type extends the 'user_right' type.
' - Create directly an 'user_right' object is forbidden.
' ('default user_right.constructor' access and 'copy user_right.constructor' access are 'Protected')
' - The 'user_right' type has only the access right to get the token.
' ('user_right.token' get-property access is 'Public' and 'user_right.token' set-property access is 'protected')
' - The 'admin_right' type has the access rights to set and to get the token.
' ('admin_right.token' get-property access and 'admin_right.token' set-property access are 'Public')
'
' An 'admin_right' object is created, and then a reference of type 'user_right' to this object is defined.
' (create directly an 'user_right' object is forbidden)
Type user_right
Public:
Declare Property token () As String '' 'Public' to authorize user_right token get
Declare Constructor () '' 'Protected' to forbid user_right object default-construction
Declare Constructor (Byref u As user_right) '' 'Protected' to forbid user_right object copy-construction
Declare Property token (Byref s As String) '' 'Protected' to forbid user_right token set
Private:
Dim As String user_right_token '' 'Private' to forbid access from outside user_right
Constructor user_right () '' Default-constructor
End Constructor
Constructor user_right (Byref u As user_right) '' Protected copy-constructor
This.user_right_token = u.user_right_token
End Constructor
Property user_right.token () As String '' Public property user_right token get
Return This.user_right_token
End property
Property user_right.token (Byref s As String) '' Protected property user_right token set
This.user_right_token = s
End Property
Type admin_right Extends user_right
Public:
Declare Property token () As String '' 'Public' to authorize admin_right token get
Declare Property token (Byref s As String) '' 'Public' to authorize admin_right token set
Property admin_right.token () As String '' Public property admin_right token get
Return Base.token '' 'Base.' to access to the base type property shadowed by this property name
End property
Property admin_right.token (Byref s As String) '' Public property admin_right token set
Base.token = s '' 'Base.' to access to the base type property shadowed by this property name
End Property
Dim As admin_right ar '' Create an admin_right type object 'ar'
ar.token = "fxm123456789" '' admin_right set the token for user_right
Print "'" & ar.token & "'" '' admin_right get the user_right token
Print
Dim Byref As user_right ur = ar '' Create a user_right type reference 'ur' to the 'ar' instance of admin_right type
Print "'" & ur.token & "'" '' user_right get its token
'ur.token = "fxm0" '' Error: Illegal member access, USER_RIGHT.TOKEN.property.set (user_right cannot set its token)
'Dim As user_right ur1 '' Error: The default constructor has no public access
'Dim As user_right ur2 = ar '' Error: Constructor has no public access
Sleep


Revision [21180]

Edited on 2016-03-13 11:45:22 by fxm [Formatting]

No Differences

Revision [20590]

Edited on 2016-02-10 16:10:38 by DkLwikki [Update link format]
Additions:
Specifies protected member access control in a ##[[KeyPgType|Type]]## or ##[[KeyPgClass|Class]]##
[[KeyPgType|Type]] //typename//
name of the ##[[KeyPgType|Type]]## or ##[[KeyPgClass|Class]]##
##**Protected:**## indicates that ##//member declarations//## following it have protected access. Protected members are accessible only from inside a member function for the ##[[KeyPgType|Type]]## or ##[[KeyPgClass|Class]]##, and classes which are derived from the ##[[KeyPgType|Type]]## or ##[[KeyPgClass|Class]]##.
##//member declarations//## following ##**Protected:**## are protected until a different access control specifier is given, like ##[[KeyPgVisPrivate|Private:]]## or ##[[KeyPgVisPublic|Public:]]##.
Members in a ##[[KeyPgType|Type]]## declaration are ##**Public:**## by default if no member access control specifier is given.
- Available only in the //[[CompilerOptlang|-lang fb]]// dialect.
- ##[[KeyPgClass|Class]]##
- ##[[KeyPgVisPrivate|Private:]]## (Access Control)
- ##[[KeyPgVisPublic|Public:]]## (Access Control)
- ##[[KeyPgType|Type]]##
Deletions:
Specifies protected member access control in a ##[[KeyPgType Type]]## or ##[[KeyPgClass Class]]##
[[KeyPgType Type]] //typename//
name of the ##[[KeyPgType Type]]## or ##[[KeyPgClass Class]]##
##**Protected:**## indicates that ##//member declarations//## following it have protected access. Protected members are accessible only from inside a member function for the ##[[KeyPgType Type]]## or ##[[KeyPgClass Class]]##, and classes which are derived from the ##[[KeyPgType Type]]## or ##[[KeyPgClass Class]]##.
##//member declarations//## following ##**Protected:**## are protected until a different access control specifier is given, like ##[[KeyPgVisPrivate Private:]]## or ##[[KeyPgVisPublic Public:]]##.
Members in a ##[[KeyPgType Type]]## declaration are ##**Public:**## by default if no member access control specifier is given.
- Available only in the //[[CompilerOptlang -lang fb]]// dialect.
- ##[[KeyPgClass Class]]##
- ##[[KeyPgVisPrivate Private:]]## (Access Control)
- ##[[KeyPgVisPublic Public:]]## (Access Control)
- ##[[KeyPgType Type]]##


Revision [19856]

Edited on 2016-01-24 17:01:25 by fxm [Added example]
Additions:
Type animal
Dim As String animalName
Protected:
Dim As Integer serialNumber
End Type
Type dog Extends animal
Dim As String masterName
Declare Sub setSerialNumber ( Byval number As Integer )
End Type
Sub dog.setSerialNumber ( Byval number As Integer )
'' This is OK. We're inside a member function of the derived type
This.serialNumber = number
End Sub
Dim As dog d
'' This is OK, animalName is public
d.animalName = "Buddy"
'' this would generate a compile error:
'' - serialNumber is protected and we're trying to access it outside its type and the derived type
'' d.serialNumber = 123456789
Deletions:
'' Example pending classes feature ...


Revision [16358]

Edited on 2012-10-05 14:09:50 by FxMwikki [This keyword is useful since fbc version 0.24]
Additions:
NOTE: This keyword is useful only since fbc version 0.24 because inheritance is then supported.
Deletions:
NOTE: This keyword is supported in the latest fbc compiler, however, its usefulness is limited since classes and inheritance are **Not** yet supported.


Revision [14467]

Edited on 2009-08-29 21:57:42 by CountingPine [Remove CamelCase links in "New to FreeBASIC"]
Additions:
- New to ""FreeBASIC""
Deletions:
- New to FreeBASIC


Revision [12470]

The oldest known version of this page was created on 2008-01-18 14:28:05 by JeffMarshall [Remove CamelCase links in "New to FreeBASIC"]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode