[Gambas-user] Structure support in Gambas 3
Benoît Minisini
gambas at ...1...
Thu May 27 00:51:42 CEST 2010
Hi,
I have just committed a new big internal change for Gambas 3 in revision
#2970: structure support.
It is not 100% finished, must most of the useful parts are there. If that
crashes your program - I will be amazed if it won't :-) - you know where to
knock.
How does it work?
To define a structure, you must declare it inside a class or a module that
way:
Public Struct <StructName>
<Var1> As <Type1>
<Var2> As <Type2>
End Struct
A structure is always public (at the moment).
A structure is a class, with only public members that are actually variables.
You can embed a structure inside an object that way:
Private <ClassVariable> As Struct <StructName>
Note the 'Struct' keyword inserted before <StructName>.
An embedded structure is not an object on its own. Its data is allocated
inside the object where it is declared. Like a "static array" (that should be
named "embedded array" actually). Note that you cannot make an "embedded
array" of static structures.
You can embed a structure inside another structure (logical, as a structure is
a class). That way, you can create russian dolls if you like. Here is a stupid
example:
Public Struct Car
Model As String
Registration As String
MaxSpeed As Float
End Struct
Public Struct Person
Name As String
Age As Integer
BirthDate As Date
FirstCar As Struct Car
SecondCar As Struct Car
End Struct
Passing structures to extern functions is not correctly supported at the
moment, but it will.
That revision has another change: objects that do not raise events do not
allocate an internal event management structure for nothing anymore. That
saves 4 pointers (16 bytes on a 32 bits system) on each object, but I'm not
100% sure I didn't do that misuse of memory ressources for nothing, so you may
have a crash.
Now Fabien has just gb.report to finish, and I we will be able to release an
alpha version of Gambas 3. :-)
But don't panic, there are a dozen of little things to do yet before the final
release... The main thing are the package manager (I want it to be sure that
it works correctly for the release, and I will need help for that), and the
ability to release incremental versions of Gambas (3.1, 3.2...) that won't be
just bug fixes like in the 2.x versions.
Enjoy it.
--
Benoît Minisini
More information about the User
mailing list