[Gambas-user] make an object of a class
Charlie
karl.reinl at ...9...
Tue Dec 21 20:13:12 CET 2004
Jochen Georges schrieb:
>Hello gambonauts,
>
>did something change?
>
NO, ... all, and several times.
Try to open your forms, make a small change, and then recompile ALL.
Mostly that works.
Amicalment
Charlie
>
>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
>
>
>
More information about the User
mailing list