[Gambas-devel] Class Properties

Randall Morgan rmorgan62 at ...176...
Thu Feb 2 01:34:38 CET 2012


Hi Benoit,

I have created a minimalist class with two properties. I expected that the
properties would be created on a per-instance bases. However, what i got
was something similar to static properties.
When I create two instances of the class setting a property in one
instance, sets it in the other.  So I know I missed something here...

I have sample code and output below.

P.S. Currently I am including the c source file in my main file to force
compiling the code. So I still need to figure out how to add a source file
to the make process.


Thanks again!

Randy



' In Gambas
Dim q As Complex
Dim v As Complex = New Complex

q = New Complex

q.Real = 10
q.Imag = 5

v.Real = 12
v.Imag = 6

Print q.Real
Print q.Imag

Print v.Real
Print v.Imag

Print q
Print v
-----------------------------------------------------
 Output
-----------------------------------------------------
12
6
12
6
(Complex 0x8b5865c)
(Complex 0x8bad4fc)



' In Class file
#ifndef __C_GSL_COMPLEX_C
#define __C_GSL_COMPLEX_C

#include "c_complex.h"
#include "gambas.h"
#include "gb_common.h"
#include "c_gsl.h"
#include <gsl/gsl_math.h>
#include <gsl/gsl_complex.h>
#include <gsl/gsl_sf.h>

#endif

// Class Properties
double real;
double imagined;

BEGIN_PROPERTY(GSLCOMPLEX_REAL)

if (READ_PROPERTY)
GB.ReturnFloat(real);
 else
real = (VPROP(GB_FLOAT));

END_PROPERTY


BEGIN_PROPERTY(GSLCOMPLEX_IMAGINED)

if (READ_PROPERTY)
GB.ReturnFloat(imagined);
 else
imagined = (VPROP(GB_FLOAT));

END_PROPERTY


/**************************************************
  Describe Class properties and methods to Gambas
**************************************************/
GB_DESC CGslComplexDesc[] =
{
    GB_DECLARE("Complex", sizeof(CCOMPLEX)),

    GB_PROPERTY("Real", "f", GSLCOMPLEX_REAL),
    GB_PROPERTY("Imag", "f", GSLCOMPLEX_IMAGINED),

    GB_END_DECLARE
};




-- 
If you ask me if it can be done. The answer is YES, it can always be done.
The correct questions however are... What will it cost, and how long will
it take?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/devel/attachments/20120201/79c04323/attachment.html>


More information about the Devel mailing list