CCar.class

The Program

This is just a class which is used in different projects.

The Code:

PUBLIC brand AS String
PUBLIC ps_power AS Integer
PUBLIC kw_power AS Float
PUBLIC price AS Float
'they must be public in this case
'otherwise WRITE and READ would cause problems

'-------------------------------
PUBLIC SUB WriteTo(hFile AS File)
'   Gambas can not save an object to a file as one thing
'   so this class has to have this method, which writes
'   every single variable to the file
'   WRITE writes in binary mode
'   PRINT writes in ascii mode
    WRITE #hFile, brand
    WRITE #hFile, ps_power
    WRITE #hFile, kw_power
    WRITE #hFile, price
END
'-------------------------------
PUBLIC SUB ReadFrom(hFile AS File)
    READ #hFile, brand
    READ #hFile, ps_power
    READ #hFile, kw_power
    READ #hFile, price
END

PUBLIC SUB _new(OPTIONAL br AS String, OPTIONAL po AS Integer, OPTIONAL pr AS Float)
  brand = br
  ps_power = po
  price = pr
END

'-------------------------------
PUBLIC SUB setBrand(x AS String)
  brand = x  
END
PUBLIC FUNCTION getBrand() AS String
  RETURN Brand 
END
'-------------------------------
PUBLIC SUB setPS_Power(x AS Integer)
  ps_power = x
END
PUBLIC FUNCTION getPS_Power() AS Integer
  RETURN ps_power
END
'-------------------------------
PUBLIC SUB setPrice(x AS Float)
  price = x
END
PUBLIC FUNCTION getPrice() AS Float
  RETURN price  
END
'-------------------------------
PRIVATE FUNCTION setKW_Power() AS Float
' this is private, because it is only used inside this class
  RETURN ps_power * 0.736
END
PUBLIC FUNCTION getKW_Power() AS Float
  RETURN setKW_Power()
END
-- JochenGeorges - 28 Dec 2004