[Gambas-user] Creating a Variant[] on the fly
Jussi Lahtinen
jussi.lahtinen at ...626...
Mon Apr 18 16:33:24 CEST 2011
You can do it this way;
Create class named InlineVariant, paste this in;
PUBLIC FUNCTION _call(...) AS Variant[]
DIM Var AS Variant
DIM aVar AS NEW Variant[]
FOR EACH var IN Param
aVar.Add(var)
NEXT
RETURN aVar
END
Then use it like this;
csvRelData.Add(InlineVariant(.LocalCardinality, .TargetCardinality),
"Cardinalities")
Jussi
On Mon, Apr 18, 2011 at 13:28, Bruce Bruen <bbruen at ...2308...> wrote:
> On Monday, April 18, 2011 06:00:14 PM Benoît Minisini wrote:
> > > Nevermind, I got around it by
> > >
> > > DIM vArray as New Variant[]
> > >
> > > varray=["Cardinalities",.LocalCardinality,.TargetCardinality]
> > > csvRelData.Add(varray,"Cardinalities")
> > > varray=["Transpose",.LocalSliceMethod,.TargetSliceMethod]
> > > csvRelData.Add(varray,"Transpose"]
> > > etc
> > >
> > > which only doubles the size of the code.
> > >
> > > But it would be nice if there was some way to cast an array as
> Variant[]
> > >
> > > :-)
> >
> > Normally that casting is automatic in Gambas 3. Which version do you use?
>
> Still on Gambas 2, frantically awaiting!
>
> gb2 correctly (according to the docs) internally casts the inline array to
> the
> type of the first element.
>
> However, because my control handles a lot of stuff of different types
> (sometimes
> I am adding an object that has its own rendering method (e.g. SliceMethod
> has
> a "StrRep" method that converts a geo-thingo (magnetometers) into a
> string) I
> need (read "want") to pass the array specifically as a Variant[].
>
> The inline array, when I coerce it into a Variant[] works beautifully. My
> desire is just a matter of reducing the calling code to its' simplest form
> (to
> lower the incidence of our coding errors!)
>
> So I will restate my desire as :
> It would be nice to be able to cast an inline array into a Variant[] rather
> than have it automatically be cast according to the first element.
>
> --
> best regards
> Bruce Bruen
>
>
> ------------------------------------------------------------------------------
> Benefiting from Server Virtualization: Beyond Initial Workload
> Consolidation -- Increasing the use of server virtualization is a top
> priority.Virtualization can reduce costs, simplify management, and improve
> application availability and disaster protection. Learn more about boosting
> the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
More information about the User
mailing list