User Tools

Site Tools


private_set_variable_private_to_a_class_module_.htm
Navigation:  Language Reference > 5 - Declaration Attributes > Variable and Entity Attributes >====== PRIVATE (set variable private to a CLASS module) ====== Previous pageReturn to chapter overviewNext page

PRIVATE

blk2blue.jpg

The PRIVATE attribute specifies that the variable on which it is placed is visible only to the PROCEDUREs defined within the source module containing the methods of the CLASS structure (whether members of the CLASS or not). This encapsulates the data from other CLASSes.

PRIVATE is also valid when used with static (threaded or non-threaded) variables outside of a CLASS structure. If a static variable is declared with the PRIVATE attribute, the compiler generates it without a public external name. Hence, it can only be used by procedures defined in the same source module.

The PRIVATE attribute is also allowed for TYPE declarations.

Example:

OneClass  CLASS,MODULE('OneClass.CLW'),TYPE

PublicVar   LONG               !Declare a Public variable

PrivateVar  LONG,PRIVATE       !Declare a Private variable

BaseProc   PROCEDURE(REAL Parm)!Declare a Public method

         END

TwoClass  OneClass             !Instance of OneClass

CODE

TwoClass.PublicVar = 1        !Legal assignment

TwoClass.PrivateVar = 1       !Illegal assignment

!OneClass.CLW contains:

MEMBER()

MAP

SomeLocalProc  PROCEDURE

END

OneClass.BaseProc  PROCEDURE(REAL Parm)

CODE

SELF.PrivateVar = Parm        !Legal assignment

SomeLocalProc  PROCEDURE

CODE

TwoClass.PrivateVar = 1       !Legal assignment

See Also:

CLASS

PROTECTED

private_set_variable_private_to_a_class_module_.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1