[Gambas-user] Re: make an object of a class
Christian Faure
christian.faurebouvard at ...357...
Tue Dec 21 18:04:52 CET 2004
El Martes, 21 de Diciembre de 2004 14:59, Jochen Georges escribió:
> Hello gambonauts,
>
> did something change?
>
> the following code worked, but now it does not.
>
> error message: "cannot load class "CCar": Bad header"
> (Fmain.class Line: car = NEW CCar("mercedes", 400))
>
> Thanks in advance
> Beste Grüße
> Jochen
>
> The Code:
> ############
> Fmain.class:
> ############
> PUBLIC car AS CCar
>
> PUBLIC SUB _new()
> car = NEW CCar("mercedes", 400)
> car.setPrice(5064.67)
> END
>
>
> PUBLIC SUB Button1_Click()
> TextLabel1.Text=
> car.getBrand() & "<br>" &
> Str(car.getPS_Power()) & " PS<br>" &
> Str(car.getPrice()) & " €"
> 'to use a method of car the following syntax has to be used:
> 'car.methodname()
> END
>
> ############
> CCar.class:
> ############
> ' Gambas class file
>
> PRIVATE brand AS String
> PRIVATE ps_power AS Integer
> PRIVATE kw_power AS Float
> PRIVATE price AS Float
>
> 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
>
> 'setKW_Power is private because
> 'it is only for internal use
> PRIVATE FUNCTION setKW_Power() AS Float
> RETURN ps_power * 0.736
> END
> PUBLIC FUNCTION getKW_Power() AS Float
> RETURN setKW_Power()
> END
>
Hi,
OPTIONAL aguments are allowed in constructors ?
Constructors "Consume" arguments (in Gambas doc)
Regards,
Christian
More information about the User
mailing list