[Gambas-user] Exposing Properties of a class..

sbungay sbungay at ...981...
Sun Jul 30 07:37:20 CEST 2006


I was trying to write a class object to encapsulate functionality and 
expose properties. What I want to do is expose a property write to 
accept a value, which then takes that value and uses it to populate 
other variables which are exposed through property reads.
   To this end I did something like this...

'-------------- Code example ---------------
PROPERTY ExposedProperty AS INTEGER
PROPERTY READ Result AS INTEGER

PRIVATE mValue as INTEGER.
PRIVATE mResult as INTEGER

PUBLIC SUB ExposedProperty_Write(Value AS INTEGER)
    mValue = Value
    mResult = Process(mValue)
END

PUBLIC Function Result_Read() AS Integer
    RETURN (mResult)
END

PRIVATE FUNCTION Process(Value AS INTEGER) AS INTEGER
   RETURN (Value * 2)
END
'-----------------

   Now in VB I would have done it something like this... (I haven't 
sparked up VB in awhile so forgive me if the syntax is not 100% 
accurate, hopefully the idea comes across...)

Private mValue AS Integer
Private mResult AS Integer

PUBLIC Property Let ExposedProperty(Value AS INTEGER)
   mValue = Value
   mResult = Process(mValue)
END SUB

Public Property GET Result() as INTEGER
    Result = mResult
END SUB

Private Function Process(Value as Integer) AS INTEGER
   Process=Value * 2
END Function

   How can I do in gambas what I know is possible in in VB?

Steve.




More information about the User mailing list