Board index » delphi » "Invalid variant conversion" error

"Invalid variant conversion" error

Hello everyone,

  when I modify a field in my Delphi app:
  with Table1 do
    begin
      Append;
      Edit;
      FieldByName('UserName').AsString := Edit1.Text;
      ...
    end;
  which <UserName> is defined as char(16).
  I get an error "Invalid variant conversion".
  what's wrong with this code?

please help me, thanks

herman

 

Re:"Invalid variant conversion" error


Hi Herman,

I already got this message which is shown you when you try to convert
a string into string, etc.
Just say:
    FieldByName('UserName').Value := Edit1.Text;
and everything will be ok.

hope i could help

    Markus

herman schrieb:

Quote
> Hello everyone,

>   when I modify a field in my Delphi app:
>   with Table1 do
>     begin
>       Append;
>       Edit;
>       FieldByName('UserName').AsString := Edit1.Text;
>       ...
>     end;
>   which <UserName> is defined as char(16).
>   I get an error "Invalid variant conversion".
>   what's wrong with this code?

> please help me, thanks

> herman

Re:"Invalid variant conversion" error


The only time I've ever gotten that error was when the field name, in
this  case "UserName", didn't exist in the database and the result of
the FieldByName call was nil.

Todd Grigsby
Panoramic Software, Inc.

Re:"Invalid variant conversion" error


Quote
Markus Munteanu wrote in message <37CA3A19.201CF...@Systema.co.at>...
>Just say:
>    FieldByName('UserName').Value := Edit1.Text;
>and everything will be ok.

No difference.
I can do this: Edit1.Text := Table1.FieldByName('UserName').AsString;
but Table1.FieldByName('UserName').<whatever> := ... always get error
"Invalid variant type conversion". the Table1.ReadOnly is set to false.
is the database mad? or I am.

sad herman

Re:"Invalid variant conversion" error


Try removing the EDIT line.  If you are performing any validation in your
table this will occur as EDIT is processed against an empty record just
assigned in your Append line.  The empty record is posted when you call
edit.  I would suggest

Quote
>   with Table1 do
>     begin
>       Append;
>         FieldByName('UserName').AsString := Edit1.Text;
         Post
>       ...
>     end;
herman <wolfe...@hotmail.com> wrote in message

news:7qd0qf$4ko6@forums.borland.com...
Quote
> Hello everyone,

>   when I modify a field in my Delphi app:
>   with Table1 do
>     begin
>       Append;
>       Edit;
>       FieldByName('UserName').AsString := Edit1.Text;
>       ...
>     end;
>   which <UserName> is defined as char(16).
>   I get an error "Invalid variant conversion".
>   what's wrong with this code?

> please help me, thanks

> herman

Re:"Invalid variant conversion" error


Quote
>   when I modify a field in my Delphi app:
>   with Table1 do
>     begin
>       Append;
>       Edit;
>       FieldByName('UserName').AsString := Edit1.Text;
>       ...
>     end;
>   which <UserName> is defined as char(16).
>   I get an error "Invalid variant conversion".
>   what's wrong with this code?

Looks like your Field "UserName" is of numeric type ...

Re:"Invalid variant conversion" error


There is nothing wrong with your code except that you do not need to call
edit immediately after append.

The error you describe is likely to be due to a character set translation
problem.

You need to check that the BDE language driver used is compatible with the
character set defined in your database.

I hope this helps.

Re:"Invalid variant conversion" error


'Invalid variant conversion' means just that, one of the types supported by
variants can't be translated to de type you give. Try creating persistent
fields for your table and assign the value that way. Just to find out if
that filed is there, you can remove them after.

Is there any code in AfterEdit, etc.?

Is there already a persistent field component and handle the event OnChange?

--
Lluis Turr, Barcelona.
http://www.teleline.es/personal/llturro

herman <wolfe...@hotmail.com> escribi en el mensaje de noticias
7qd0qf$4...@forums.borland.com...

Quote
> Hello everyone,

>   when I modify a field in my Delphi app:
>   with Table1 do
>     begin
>       Append;
>       Edit;
>       FieldByName('UserName').AsString := Edit1.Text;
>       ...
>     end;
>   which <UserName> is defined as char(16).
>   I get an error "Invalid variant conversion".
>   what's wrong with this code?

> please help me, thanks

> herman

Other Threads