Kobus wrote:
I am playing around with Delphi XE6 and have run into the
EConvertError (see subject)
This is a locale issue. You are formatting a TDateTime using a specific
format, but then you are using the version of StrToTime() that uses the OS
locale for parsing. The error means the string you are parsing does not
match what the OS is expecting. In particular, the OS's expected thousands
and/or decimal separator is likely different than what the string is using.
First off, why are you formatting a TDateTime to a string and then back to
a TDateTime? You don't need that at all. Just store the result as-is:
T1d := Now - StartTime;
In cases where you actually do need to parse a date/time string, use the
version of StrToTime() that takes a TFormatSettings as input so you can specify
the exact format of the string:
var
fmt: TFormatSettings;
fmt := TFormatSettings.Create;
fmt.TimeSeparator := ':'
fmt.DecimalSeparator := '.';
T1d := StrToTime(FormatDateTime('hh:mm:ss.zzz', Now - StartTime, fmt), fmt);
I wrote a little program that will measure the time that a rat spend
on a specific activity (down to milliseconds) (working with scientific
students).
I would not suggest using TDateTime for that. I would suggest using GetTickCount/64()
or TStopWatch instead:
uses
..., Windows;
var
Start, Elapsed: DWORD;
Start := GetTickCount;
// do activity ...
Elapsed := GetTickCount - Start;
uses
..., Windows;
var
Start, Elapsed: DWORD;
Start := GetTickCount;
// do activity ...
Elapsed := GetTickCount - Start;
uses
..., System.Diagnostics;
var
SW: TStopWatch;
Elapsed: Int64;
SW := TStopWatch.StartNew;
// do activity ...
SW.Stop;
Elapsed := SW.ElapsedMilliseconds;
--
Remy Lebeau (TeamB)
Connect with Us