[fpc-pascal] Implicit conversion problem with TDate type

LacaK lacak at zoznam.sk
Wed Nov 2 11:50:04 CET 2016


Dňa 2.11.2016 o 11:38 Michael Van Canneyt napísal(a):
>
>
> On Wed, 2 Nov 2016, Gabor Boros wrote:
>
>> Hi All,
>>
>> I use MWA's IBX for Firebird connection and have problem with date 
>> parameters. Tony provided to me a test program a suggested write to 
>> the FPC list. The simple test program is:
>>
>> program Project1;
>>
>> uses Variants, Sysutils;
>>
>> var V: variant;
>>    D: TDate;
>>
>> begin
>>  D := EncodeDate(2016,10,20);
>>  V := D;
>>  writeln('date is ',VarType(D));
>> end.
>>
>> The result is: "date is 5" (varDouble)
>>
>> If modify D: TDate; to D: TDateTime; the result is "date is 7" (varDate)
>>
>> I (We) missed something or is this a bug?
>
> Only TDateTime is automatically converted correctly to Variant.
> TDate and TTime are distinct types and not automatically converted.
> They are seen as doubles (the original type of TDateTime).
>
> If Delphi prints another result, then we can look at fixing the 
> implementation.
Delphi7 prints 5
Of course you can use V := TDateTime(D); then prints 7

-Laco.




More information about the fpc-pascal mailing list