Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2005-06

A variant which stored string convert to DateTime failure in FPC 2.0.0

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

alphax

A variant which stored string convert to DateTime failure in FPC 2.0.0.

There is a simple program can reproduce this problem.

//=============================================
program test_var_dt;
{$IFDEF FPC}
  {$MODE OBJFPC}
{$ENDIF}
uses
  SysUtils, Variants;
var
  DT: TDateTime;
  S: string;
   V: Variant;
   C: Currency;
begin
  V := '1.0';
  C := V;
  WriteLn(CurrToStr(C));
  S := DateTimeToStr(Now());
  V := S;
  DT := V;
  WriteLn(DateTimeToStr(DT));
  ReadLn;
end.
//=============================================

The runtime error message is

An unhandled exception occurred at $0041334D :
EVarianterror :
....

I am trace into the source(2.0.0 release), in the rtl\objpas\cvarutil.inc I found, the function implementation of VariantToDate is incomplete, lost the string(and widestring) convert to result case:

Function VariantToDate(Const VargSrc : TVarData) : TDateTime;
begin
  Try
    With VargSrc do
      Case (VType and VarTypeMask) of
        VarSmallInt: Result:=FloatToDateTime(VSmallInt);
        VarShortInt: Result:=FloatToDateTime(VShortInt);
        VarInteger : Result:=FloatToDateTime(VInteger);
        VarSingle  : Result:=FloatToDateTime(VSingle);
        VarDouble  : Result:=FloatToDateTime(VDouble);
        VarCurrency: Result:=FloatToDateTime(VCurrency);
        VarDate    : Result:=VDate;
        VarOleStr  : NoWideStrings; //<<==== here
        //varString: <<======= leak a varString
        VarBoolean : Result:=FloatToDateTime(Longint(VBoolean));
        VarByte    : Result:=FloatToDateTime(VByte);
        VarWord    : Result:=FloatToDateTime(VWord);
        VarLongWord    : Result:=FloatToDateTime(VLongWord);
        VarInt64   : Result:=FloatToDateTime(VInt64);
        VarQWord   : Result:=FloatToDateTime(VQword);
    else
      VariantTypeMismatch;
    end;
  except
    On EConvertError do
      VariantTypeMismatch;
    else
      Raise;
  end;
end;

and other function also has this problem

alphax

Reply by email