[Gambas-user] Component, GB.Raise, Event, Collection argument
Benoit Minisini
gambas at ...1...
Fri Sep 3 08:43:03 CEST 2004
On Friday 03 September 2004 05:21, Christian Faure wrote:
> Hello Benoit!
Hi,
>
> i'am working on a gambas-component
So you should have sent this mail on the development mailing-list :-)
> No problems when using String parameters, but
> when use a Collection as parameter, i get an unexpected error an program
> stop.
>
> my problem is how to pass a Collection as event param
>
> C code:
> ...
> DECLARE_EVENT(MyEvent);
>
> static void test (void *_object){
> GB_COLLECTION * MyCollection;
No. --> 'GB_COLLECTION MyCollection'.
GB_COLLECTION is already a pointer. Look in gambas.h.
> GB_VARIANT_VALUE MyValue;
> //create a new collection object
> GB.Collection.New ( MyCollection , GB_COMP_TEXT );
--> GB.Collection.New ( &MyCollection , GB_COMP_TEXT );
And your object is created with a zero reference counter. You must reference
it:
---> GB.Ref(MyCollection);
> //add a string item
> MyValue._string.value="MyStringValue";
This does not work. You must create a GB_VARIANT string value. There is no API
to create such a value at the moment. You must take it from the interpreter
stack.
I could create such an API, unless this is only for a test. Tell me what you
want to do exactly.
> GB.Collection.Set ( MyCollection, "MyKey", 5 , &MyValue);
> //Raise event with collection param
> GB.Raise(THIS, MyEvent, 1, GB_T_OBJECT, MyCollection);
If you don't use anymore the collection, you must dereference it:
---> GB.Unref((void **)&MyCollection);
> }
> ...
> GB_DESC CMyClassDesc[] =
> {
> ...
> GB_EVENT("MyEvent", NULL, "(MyCollection)o", &MyEvent),
> ...
> }
>
> Gambas code:
> ...
> sub MyComp_MyEvent(MyCollection as object)
> print MyCollection.Count
> end sub
> ...
>
> Can you help me?
> What is wrong?
> Are correct the sequence for create and adding an item to a Collection?
Look at the Settings class (gbx_c_settings.c). It uses a collection to store
program settings.
Regards,
--
Benoit Minisini
mailto:gambas at ...1...
More information about the User
mailing list