Link to home
Start Free TrialLog in
Avatar of ISIGest
ISIGestFlag for Italy

asked on

Variant and TDateTime

Hi, how i can check il a "Variant" Parameter or Variable is a TDateTime or a Double?
Avatar of Shanmuga Sundaram D
Shanmuga Sundaram D
Flag of India image

That link didn't work for me... anyway, you can check what type a variant holds, by using the VarType function... see the example below.

regards
Hypo
procedure TForm1.Button1Click(Sender: TObject);
var aVar : Variant;
    aDateTime : TDateTime;
    aDouble : Double;
begin
  aVar := aDateTime;
  Case VarType(aVar) of
    varDate: ShowMessage('Variant is a date');
    varDouble: ShowMessage('Variant is a double');
    else ShowMessage('Variant is of some other type');
  end;
 
  aVar := aDouble;
  Case VarType(aVar) of
    varDate: ShowMessage('Variant is a date');
    varDouble: ShowMessage('Variant is a double');
    else ShowMessage('Variant is of some other type');
  end;
end;

Open in new window

case VarType(Param) of
  varDate: ShowMessage('Date : ' + FormatDateTime('dd/mm/yyyy hh:nn:ss', VarToDateTime(Param)));
  varDouble: ShowMessage('Double: ' + FloatToStr(Param));
end;
Avatar of ISIGest

ASKER

The VarType "varDouble" could not be a valid TDateTime but a normal Double value.
how did you get the value ?
that will determine your approach !
ISIGest: Sorry, but I really don't understand your comment... It didn't work for you?  you got a runtime error? Can you post some of your code, with an explaination of what you are trying to do, and what results you'd expect if it was working?
Avatar of ISIGest

ASKER

Ok...sorry...
If I test the variant variable with a VarType() function, the result can be varDouble if the variant value is a TDateTime like "15/05/2009 10.34" (in Double value format = 39948,440278), but it can be also a normal Double value like 350,25 or other value like 8540,69.
Ok, now how i can check if this value is a "valid" Double for a valid TDateTime?

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Hypo
Hypo
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial