On Fri, 11 Mar 2005, Kristof Vydt wrote:
 
> Is there a way to use some generic array type, so that I don't have to
> duplicate all my functions for all datatypes ?

You could make an array of "variants" in which you declare a structure
like:

type tVariant
  type as smallint
  data as string
end type

and then declare your function as: 
Join ( a() As tVariant, ByVal separator As String ) As String

You'd store all data types as string representations of their native 
types, and you would identify the types as smallints according to the 
defined constants like so:

define V_INTEGER 1
define V_STRING 2
define V_DATE 3
...

You'd use it like so:

dim sResult as string
dim a() as tVariant

redim a(100)

a(1).type = V_DATE
a(1).data = "20050310"
a(2).type = V_DATE
a(2).data = "17760704"
...

sResult = Join (a, ";")

Before your function would operate on the data part, it would check the
type and call the appropriate function to deal with it. You might even
declare the type as a type containing an array instead (if you knew that
all elements of your array would be the same type)

define type tVariantArray
  type as smallint
  data() as string
end type

You can even implement totally different types of variables this way too.
A "BLOB" (binary large object) might be implemented as a hexadecimal-coded
string, or it might be a pointer into a file or a filename itself. 

It's not as speedy as using MapBasic native types, but that's just an 
issue with MapBasic. The concept is basically what faster languages use 
anyway, and if you can trade speed for algorithmic simplicity, you might 
consider it.

Of course, from the looks of your Join() function, I would simply just 
make sure that I pass the string representations of the array elements and 
just use a string array in join. But if you think outside the box, there 
are always alternatives!

- Bill Thoen



---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 15663

Reply via email to