[Gambas-devel] Returning Non-standard type arrays

Benoît Minisini gambas at ...1...
Tue Feb 28 23:26:01 CET 2012


Le 28/02/2012 19:25, Randall Morgan a écrit :
> Hi,
>
> Can someone show a some sample code for creating and returning a variant
> array. I have a method that will return a two element array and I need a
> Float in index 0 and an integer in index 1 or the variant array. I've
> tried looking at code in the DBUS component but can't seem to get an
> handle on it.

For which GSL function do you need that?

>
> In another method I need to return an array of objects of the type on
> one of my classes "Complex" I seem to have figured out how to return
> arrays of ints, float, etc but I am having trouble with objects and
> complex types.
>
> Any samples or help would be greatly appreciated.

The datatype for an array of complex is "Complex[]".

Then you create your array with the GB.Array.New() API, by using 
GB.FindClass("Complex") as second argument.

Once done, you have a array of Complex that is actually an array of 
pointers pointing at Complex Gambas object all initialized to NULL.

You must create the Complex objects, and then put it inside the 
Complex[] array that way:

	GB_ARRAY array;

	GB.Array.New(&array, GB.FindClass("Complex"), size);

	// Create a new Complex

	*GB.Array.Get(TheArray, index) = TheComplexPointer;

	GB.Ref(TheComplexPointer);

Don't forget to reference the Complex object when you put it inside the 
array.

Regards,

>
> Thanks,
>
> Randall
>
>
> --
> 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?
>
>
> ------------------------------------------------------------------------------
> Keep Your Developer Skills Current with LearnDevNow!
> The most comprehensive online learning library for Microsoft developers
> is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
> Metro Style Apps, more. Free future releases when you subscribe now!
> http://p.sf.net/sfu/learndevnow-d2d
>
>
>
> _______________________________________________
> Gambas-devel mailing list
> Gambas-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-devel


-- 
Benoît Minisini




More information about the Devel mailing list