Programming => Packages and Libraries => Ported from Delphi/Kylix => Topic started by: Elphi on February 13, 2007, 12:38:47 am

Title: EVariantTypeCastError
Post by: Elphi on February 13, 2007, 12:38:47 am
I get an EVariantTypeCastError: could not convert variant of type (String) into type (Byte) in the following method:
Code: [Select]

Read a variant from a binary stream.
procedure TYMBinaryStreamSerializer.ReadVariant(var AVariant: Variant; const ATag: String = '');
  VarTyp: LongInt;
  Str: String;
  WStr: WideString;
  DT: TDateTime;
  Dbl: Double;

  case VarTyp of
                            varOleStr: begin
                                         AVariant := WStr;
                              varDate: begin
                                         AVariant := DT;
    varDouble, varSingle, varCurrency: begin
                                         AVariant := Dbl;
                              varNull: AVariant := Null;
                             varEmpty: AVariant := Unassigned;
                                  else begin
                            >>>      AVariant := VarAsType(Str, VarTyp);   <<<
                                       end; {else}
  end; {case}

end; {ReadVariant}

The VarTyp read from the stream was: 17. The string read was: '1'.

Any suggestions to make this work?
TinyPortal © 2005-2018