[Gambas-user] Types? Records?

Rob sourceforge-raindog2 at ...94...
Mon Jul 28 17:39:33 CEST 2003


On Monday 28 July 2003 10:54, Ahmad Kamal wrote:
>     Does Gambas support creating Types (records in C) to store data?

You would use classes for that.  I don't know how to get a binary formatted 
concatenation of the whole record like in C automatically, but it shouldn't 
be too tough to write a function to do that and make it a property get 
function.  See the following code from theeasygambasdoku:

http://www.binara.com/gambas-wiki/pub/Gambas/HowDoIMakeAnObjectOfAClass/ccar.html

It's worth mentioning that Gambas may have changed somewhat since that code 
was written, and Benoit plans in the near future to allow classes to have 
property functions like controls do in addition to public variables which 
they have already.  If you wrote a class file, say CThingy.class, like so:

PUBLIC Foo as Integer
PUBLIC Bar as Float
PUBLIC Baz as String

PUBLIC SUB _new(OPTIONAL initFoo as Integer, OPTIONAL initBar as Float, 
OPTIONAL initBaz as String)
	Foo = initFoo
	Bar = initBar
	Baz = initBaz
END

you would then be able to go 

dim myThingy as CThingy
myThingy = new CThingy(5, 3.14159, "This is a string")
Message.Info("The cow says: " & myThingy.Baz)
' etc.

For simpler types you could just use a collection as you would use a hash in 
Perl.

Rob





More information about the User mailing list