Thanks
> What is the best way to convert a variant to an integer or a float?
> There is no VarToFloat or VarToInt.
Just copy it into a float or integer variable.
--
Marc Rohloff [TeamB]
marc rohloff -at- myrealbox -dot- com
> What is the best way to convert a variant to an integer
> or a float? There is no VarToFloat or VarToInt.
Variant has various conversion operators implemented. Just assign it
directly, ie:
Variant v1 = 12345;
int i = v1;
v = 12345.0;
float f = v;
Gambit
Thanks.
> There are functions for VarToStr, etc.
They are used by the VCL internally.
> Sometimes I use pass variants into routines where the type is
> of integer and it works, but I find it safest to assign the variant
> to an integer variable and pass the new variable to the funtion.
If the function takes an 'int' as a parameter, then there is no need to use
a separate variable. You can pass the Variant to the parameter directly,
and it will convert the same way as it does being assigned to a variable.
> More specifically I am speaking of situations where I am passing a
> tfield as in " ds.fieldbyname('var').value " as an integer value
parameter.
TField has its own conversion properties, such as AsInteger, ie:.
function(ds.FieldByName('var').AsInteger);
> This is not a stable practice even though the value is a number at the
> time of the operation.
Why do you think it is unstable?
> It seems as though you are safer passing the field value to a variable
> prior to passing to the function.
There is no difference between doing that and passing the Variant to the
parameter directly.
Gambit
D,
I think it is good practice to avoid the extra overhead of
variants, wherever possible.
--JohnH
"D-Fan" <D-...@TheAntiSpam.com> wrote in message
news:44971FFE...@TheAntiSpam.com...
VarAsType() returns a new Variant. The conversion operators of Variant
already perform internal casting similar to VarAsType(), so there is no need
to make more temporary copies than are already being used implicitally.
Gambit