Board index » delphi » "Invalid variant type conversion"

"Invalid variant type conversion"

Hi everyone,

I get
    "Invalid variant type conversion"
on:
    IF
DmCoupling.TblPIA_ID.Locate(CCData.IDFieldList,IDFldData,[loCaseInsensitive]
) THEN
with:
    CCData.IDFieldList = 'Personeelsnummer'
    IDFldData[0] := '78'

Declarations:
   IDFldData         : Variant;
   CCData.IDFieldList: String;

IDFldData was created with
    IDFldData  := VarArrayCreate([0,NKeyFields-1],varVariant);
    where NKeyFields=1
and filled with
    FOR N := 1 TO NKeyFields DO
      BEGIN
        ImpFldCont     := ImpFldData[DBIntNumID[N]];
        IDFldData[N-1] := ImpFldCont;  { string value '78' }
      END; { For all keyfields }

TblPIA_ID points to a table
with key field InternID is an integer.

It looks like the integer and the '78' don't match.
What can I do to prevent this? The VarArrayCreate must contain 'varVariant'
as second parameter, because I do not know beforehand what types
I'm gonna get.

Thanks,
Jan

 

Re:"Invalid variant type conversion"


Quote
"Jan Doggen" <j.dog...@qsa.nl> wrote in message

news:Ro705.26402$k22.248835@flipper...
Quote
> Hi everyone,

> I get
>     "Invalid variant type conversion"
> on:
>     IF

DmCoupling.TblPIA_ID.Locate(CCData.IDFieldList,IDFldData,[loCaseInsensitive]

Likely the problem is that IDFFldData is not initialized properly, see
below.

Quote
> ) THEN
> with:
>     CCData.IDFieldList = 'Personeelsnummer'
>     IDFldData[0] := '78'

> Declarations:
>    IDFldData         : Variant;
>    CCData.IDFieldList: String;

> IDFldData was created with
>     IDFldData  := VarArrayCreate([0,NKeyFields-1],varVariant);
>     where NKeyFields=1
> and filled with
>     FOR N := 1 TO NKeyFields DO

This loop will never initialize element 0 of your array.

Quote
>       BEGIN
>         ImpFldCont     := ImpFldData[DBIntNumID[N]];
>         IDFldData[N-1] := ImpFldCont;  { string value '78' }
>       END; { For all keyfields }

> TblPIA_ID points to a table
> with key field InternID is an integer.

> It looks like the integer and the '78' don't match.
> What can I do to prevent this? The VarArrayCreate must contain
'varVariant'
> as second parameter, because I do not know beforehand what types
> I'm gonna get.

> Thanks,
> Jan

Other Threads