Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Private properties in defined class
Message
From
18/09/2002 21:42:25
 
 
To
18/09/2002 20:56:08
Jordan Pastourel
Worksafe Management Systems
Toowong, Australia
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00702088
Message ID:
00702098
Views:
20
ListArray is not accessed directly by objectGet.ListArray. It always pass through the ListArray_ACCESS procedure. So, let's say that you want to keep an internal counter on the number of times that ListArray is accessed, you would do this:
DEFINE CLASS objectGet as Custom OLEPUBLIC
   PROTECTED AccessCnt
   AccessCnt = 0
   ListArray = 100

   PROCEDURE ListArray_ACCESS && Access method
      THIS.AccessCnt = THIS.AccessCnt + 1
      RETURN THIS.ListArray
   ENDPROC

   PROCEDURE ListArray_ASSIGN && Assign method
      LPARAMETERS tAssign  && Required to accept value
         THIS.ListArray = tAssign
   ENDPROC

   FUNCTION GetCnt
      RETURN THIS.AccessCnt
   ENDFUNCTION
ENDDEFINE
Then this code would yield the following results:
oGet = CREATEOBJECT ("objectGet")
? oGet.ListArray && Display 100
oGet.ListArray = 50
? oGet.ListArray && Display 50
? oGet.GetCnt () && Display 2
Also note the use of AccessCnt. It shows an alternate way of accessing a private property via an accessor method. This is probably what you had in mind at the first place. I prefer the preceding method though, because it is more self-documenting - I know just by reading the code that _ACCESS and _ASSIGN methods are accessors for a local property while forcing the caller to pass by my accessor to get what they want.

HTH

>that's exactly what i want to do, but i want to stop the ListArray from being accessed through: objectGet.ListArray
>
>how is this done?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform