wxRuby Documentation Home

# Wx::Variant

The Variant class represents a container for any type.
A variant’s value can be changed at run time, possibly to a different type of value.

As standard, Variant can store values of type bool, char, double, long, string,
string list, time, date, void pointer, list of strings, and list of variants. However, an application can extend Variant’s capabilities by deriving from the class VariantData and using the VariantData form of the Variant constructor or assignment operator to assign this data to a variant. Actual values for user-defined types will need to be accessed via the VariantData object, unlike the case for basic data types where convenience functions such as GetLong can be used.

This class is useful for reducing the programming for certain tasks, such as an editor
for different data types, or a remote procedure call protocol.

An optional name member is associated with a Variant. This might be used, for example, in CORBA
or OLE automation classes, where named parameters are required.

## Derived from

Object

## See also

VariantData

## Methods

- Variant.new
- Variant#append
- Variant#clear_list
- Variant#convert
- Variant#get_count
- Variant#delete
- Variant#get_array_string
- Variant#get_bool
- Variant#get_char
- Variant#get_data
- Variant#get_date_time
- Variant#get_double
- Variant#get_long
- Variant#get_name
- Variant#get_string
- Variant#get_type
- Variant#get_void_ptr
- Variant#get_wx_object_ptr
- Variant#insert
- Variant#is_null
- Variant#is_type
- Variant#is_value_kind_of
- Variant#make_null
- Variant#make_string
- Variant#member
- Variant#null_list
- Variant#set_data
- wxVariant::operator char
- wxVariant::operator double
- wxVariant::operator wxString
- wxVariant::operator wxDateTime

### Variant.new

Variant.new(%(arg-type)Variant% variant)

Copy constructor.

Variant.new(%(arg-type)char% value, String name = "") Variant.new(%(arg-type)String% value, String name = "")

Construction from a string value.

Variant.new(%(arg-type)char% value, String name = "")

Construction from a character value.

Variant.new(%(arg-type)Integer% value, String name = "")

Construction from an integer value. You may need to cast to (long) to
avoid confusion with other constructors (such as the bool constructor).

Variant.new(%(arg-type)Boolean% value, String name = "")

Construction from a boolean value.

Variant.new(%(arg-type)Float% value, String name = "")

Construction from a double-precision floating point value.

Variant.new(%(arg-type)List% value, String name = "")

Construction from a list of Variant objects. This constructor
copies value, the application is still responsible for
deleting value and its contents.

Variant.new(%(arg-type)% value, String name = "")

Construction from a void pointer.

Variant.new(%(arg-type)Object% value, String name = "")

Construction from a Object pointer.

Variant.new(%(arg-type)VariantData% data, String name = "")

Construction from user-defined data. The variant holds onto the data pointer.

Variant.new(%(arg-type)DateTime% val, String name = "")

Construction from a DateTime.

Variant.new(%(arg-type)ArrayString% val, String name = "")

Construction from an array of strings. This constructor copies value and its contents.

Variant.new(%(arg-type)DATE_STRUCT% val, String name = "")

Construction from a odbc date value. Represented internally by a DateTime value.

Variant.new(%(arg-type)TIME_STRUCT% val, String name = "")

Construction from a odbc time value. Represented internally by a DateTime value.

Variant.new(%(arg-type)TIMESTAMP_STRUCT% val, String name = "")

Construction from a odbc timestamp value. Represented internally by a DateTime value.

destructor()

Destructor.

### Variant#append

append(%(arg-type)Variant% value)

Appends a value to the list.

### Variant#clear_list

clear_list()

Deletes the contents of the list.

### Variant#convert

Boolean convert(%(arg-type)Integer% value) Boolean convert(%(arg-type)Boolean% value) Boolean convert(%(arg-type)Float% value) Boolean convert(%(arg-type)String% value) Boolean convert(%(arg-type)char% value) Boolean convert(%(arg-type)DateTime% value)

Retrieves and converts the value of this variant to the type that value is.

### Variant#get_count

Integer get_count()

Returns the number of elements in the list.

### Variant#delete

Boolean delete(%(arg-type)Integer% item)

Deletes the zero-based item from the list.

### Variant#get_array_string

ArrayString get_array_string()

Returns the string array value.

### Variant#get_bool

Boolean get_bool()

Returns the boolean value.

### Variant#get_char

char get_char()

Returns the character value.

### Variant#get_data

VariantData get_data()

Returns a pointer to the internal variant data.

### Variant#get_date_time

DateTime get_date_time()

Returns the date value.

### Variant#get_double

double get_double()

Returns the floating point value.

### Variant#get_long

Integer get_long()

Returns the integer value.

### Variant#get_name

String get_name()

Returns a constant reference to the variant name.

### Variant#get_string

String get_string()

Gets the string value.

### Variant#get_type

String get_type()

Returns the value type as a string. The built-in types are: bool, char, date, double, list, long, string, stringlist, time, void*.

If the variant is null, the value type returned is the string ``null" (not the empty string).

### Variant#get_void_ptr

get_void_ptr()

Gets the void pointer value.

### Variant#get__object_ptr

get__object_ptr()

Gets the Object pointer value.

### Variant#insert

insert(%(arg-type)Variant% value)

Inserts a value at the front of the list.

### Variant#is_null

Boolean is_null()

Returns true if there is no data associated with this variant, false if there is data.

### Variant#is_type

Boolean is_type(%(arg-type)String% type)

Returns true if type matches the type of the variant, false otherwise.

### Variant#is_value_kind_of

Boolean is_value_kind_of(%(arg-type)ClassInfo type% type)

Returns true if the data is derived from the class described by type, false otherwise.

### Variant#make_null

make_null()

Makes the variant null by deleting the internal data.

### Variant#make_string

String make_string()

Makes a string representation of the variant value (for any type).

### Variant#member

Boolean member(%(arg-type)Variant% value)

Returns true if value matches an element in the list.

### Variant#null_list

null_list()

Makes an empty list. This differs from a null variant which has no data; a null list
is of type list, but the number of elements in the list is zero.

### Variant#set_data

set_data(%(arg-type)VariantData% data)

Sets the internal variant data, deleting the existing data if there is any.

### Variant#=

operator $=$(%(arg-type)Variant% value) operator $=$(%(arg-type)VariantData% value) operator $=$(%(arg-type)String% value) operator $=$(%(arg-type)char% value) operator $=$(%(arg-type)char% value) operator $=$(%(arg-type)Integer% value) operator $=$(%(arg-type)Boolean% value) operator $=$(%(arg-type)Float% value) operator $=$(%(arg-type)% value) operator $=$(%(arg-type)List% value) operator $=$(%(arg-type)DateTime% value) operator $=$(%(arg-type)ArrayString% value) operator $=$(%(arg-type)DATE_STRUCT% value) operator $=$(%(arg-type)TIME_STRUCT% value) operator $=$(%(arg-type)TIMESTAMP_STRUCT% value)

Assignment operators.

### Variant#==

Boolean operator $==$(%(arg-type)Variant% value) Boolean operator $==$(%(arg-type)String% value) Boolean operator $==$(%(arg-type)char% value) Boolean operator $==$(%(arg-type)char% value) Boolean operator $==$(%(arg-type)Integer% value) Boolean operator $==$(%(arg-type)Boolean% value) Boolean operator $==$(%(arg-type)Float% value) Boolean operator $==$(%(arg-type)% value) Boolean operator $==$(%(arg-type)List% value) Boolean operator $==$(%(arg-type)ArrayString% value) Boolean operator $==$(%(arg-type)DateTime% value)

Equality test operators.

### Variant#!=

Boolean operator $!=$(%(arg-type)Variant% value) Boolean operator $!=$(%(arg-type)String% value) Boolean operator $!=$(%(arg-type)char% value) Boolean operator $!=$(%(arg-type)char% value) Boolean operator $!=$(%(arg-type)Integer% value) Boolean operator $!=$(%(arg-type)Boolean% value) Boolean operator $!=$(%(arg-type)Float% value) Boolean operator $!=$(%(arg-type)% value) Boolean operator $!=$(%(arg-type)List% value) Boolean operator $!=$(%(arg-type)ArrayString% value) Boolean operator $!=$(%(arg-type)DateTime% value)

Inequality test operators.

### Variant#[]

Variant operator $[]$(%(arg-type)Integer% idx)

Returns the value at idx (zero-based).

Variant operator $[]$(%(arg-type)Integer% idx)

Returns a reference to the value at idx (zero-based). This can be used
to change the value at this index.

### Variant::operator char

char operator char()

Operator for implicit conversion to a char, using Variant#get_char.

### Variant::operator double

double operator double()

Operator for implicit conversion to a double, using Variant#get_double.

Integer operator long()

Operator for implicit conversion to a long, using Variant#get_long.

### Variant::operator String

String operator _string()

Operator for implicit conversion to a string, using Variant#make_string.

### Variant::operator void*

operator void*()

Operator for implicit conversion to a pointer to a void, using Variant#get_void_ptr.

### Variant::operator DateTime

operator _date_time()

Operator for implicit conversion to a pointer to a DateTime, using Variant#get_date_time.

[This page automatically generated from the Textile source at 2023-06-09 00:45:34 +0000]