[Gambas-user] Optional parameters for Read accessors
Benoît Minisini
g4mba5 at gmail.com
Mon Jun 21 11:24:59 CEST 2021
Le 21/06/2021 à 04:08, bb a écrit :
> I'm pushing the boundaries again.
>
> Sometimes we have a property that has more than one state variable. An
> easy example is one where its original value or "at some point" is set
> by the property Write accessor and its current state variable value is
> variable perhaps based on user activity.
>
> What I am trying to achieve is a way to have the property Read accessor
> accept on optional parameter that will determine which of those values
> is returned.
>
> Of course, the obvious answer is to use another property or function to
> return a specific state variable.
>
> However it would be "neater" to have this in the natural accessor
> method.
> Private Sub MyProp_Read(Optional orig As Boolean=False) as Integer
> If orig then
> Return $originalValue
> Else
> Return $currentValue
> EndIf
> End
> or something like that. In my current case the situation is much more
> complex, hence the question, but that example encapsulates what I am
> trying to achieve.
>
> At the moment, trying this results in a "_Read declaration does not
> match" error from the compiler, naturally.
>
> Is this viable?
> Thoughts?
>
> regards
> bruce
>
Then you have to replace your "MyProp" property by a "GetMyProp"
function with your optional parameter, like you would do in Java.
Regards,
--
Benoît Minisini
More information about the User
mailing list