Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi TimeStampToDateTime - difference Delphi5 - Delphi7 (https://www.delphipraxis.net/82289-timestamptodatetime-difference-delphi5-delphi7.html)

Cadere 10. Dez 2006 12:30


TimeStampToDateTime - difference Delphi5 - Delphi7
 
Hello,

On my computer I recently installed Delphi 7.
In my latest project I used to use this routine:

// in other routine: Starttime := GetTickCount();
// in other routne: perform action

function CalcTimeNeeded : string;
var Starttime,
delta : Comp;

begin
delta := GetTickCount() - StartTime;
result := FormatDateTime('hh"h":nn"m":ss"s":zzz"ms"',TimeSta mpToDateTime(MSecsToTimeStamp(delta)));
end;

In Delphi5 this works perfect. In Delphi7 I get an exception-error on TimeStampToDateTime.
How can I get this working in Delphi7 (or later???)

Thanks in Advance.
Jan.

mkinzler 10. Dez 2006 12:37

Re: TimeStampToDateTime - difference Delphi5 - Delphi7
 
What exception ist thrown?

marabu 10. Dez 2006 13:00

Re: TimeStampToDateTime - difference Delphi5 - Delphi7
 
Hi Jan,

you should get rid of the global variable StartTime and there is no need to employ the TTimeStamp structure:

Delphi-Quellcode:
function TicksToStr(ticks: Cardinal): String;
begin
  Result := FormatDateTime('hh"h":nn"m":ss"s":zzz"ms"', ticks / MSecsPerDay);
end;
Kind regards

Cadere 10. Dez 2006 13:07

Re: TimeStampToDateTime - difference Delphi5 - Delphi7
 
Hi

The exception raised is:
Project ... raised exception class EConvertError with message "0.8906" is not a valid timestamp".

Nice routine, marabu, with TicksToStr.. I'm going to try it.

Thanks.
Jan.

mkinzler 10. Dez 2006 13:09

Re: TimeStampToDateTime - difference Delphi5 - Delphi7
 
Zitat:

The exception raised is:
Project ... raised exception class EConvertError with message "0.8906" is not a valid timestamp".
It seams your system settings aren't appropriate ( decimal separator isn't '.')

marabu 10. Dez 2006 13:16

Re: TimeStampToDateTime - difference Delphi5 - Delphi7
 
Hi Markus,

there is nothing wrong with that - it is an internal message displayed, after all. MSecsToTimeStamp() is implemented differently under D7 and enforces the rule that the Date part of a TimeStamp must be >= 1. D5 didn't care about this.

Kind Regards


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:15 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz