Lazarus

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 = '');
var
  VarTyp: LongInt;
  Str: String;
  WStr: WideString;
  DT: TDateTime;
  Dbl: Double;
begin
  ReadLongInt(VarTyp);

  case VarTyp of
                            varOleStr: begin
                                         ReadWideString(WStr);
                                         AVariant := WStr;
                                       end;
                              varDate: begin
                                         ReadDateTime(DT);
                                         AVariant := DT;
                                       end;
    varDouble, varSingle, varCurrency: begin
                                         ReadDouble(Dbl);
                                         AVariant := Dbl;
                                       end;
                              varNull: AVariant := Null;
                             varEmpty: AVariant := Unassigned;
                                  else begin
                                         ReadString(Str);
                            >>>      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