1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
type
oChrono = object
TopDepart,Duree : longWord;
procedure Top;
function Mis(Format : byte) : string;
// Format=1 renvoie par ex 12h 15m 4s 45ms
// Format=2 renvoie 12:15:04:045
// Format=3 renvoie 44104045 ms
end;
var monChrono1,monChrono2,monChrono3 : oChrono;
procedure oChrono.Top; // procédure à appeler à l'endroit du code où l'on veut déclencher le Top-Départ
begin
TopDepart:=GetTickCount;
end;
function oChrono.Mis(Format : byte) : String; // Fonction à appeler à l'endroit du code qui marque la fin du truc à chronémétrer et pour afficher le temps écoulé
var msp,he,mi,se,ms : longWord; s : string; t : shortString;
function calibre(t : shortString; n : byte) : shortString;
begin
while length(t)<n do t:='0'+t;
calibre:=t;
end;
begin
Duree:= GetTickCount-TopDepart; // millisecondes passées
//Duree:=12*60*60*1000 + 15*60*1000 + 4*1000 + 45; //12h 15m 4s 45ms
msp:=Duree;
ms:= msp mod 1000; msp:= msp div 1000;
se:= msp mod 60; msp:= msp div 60;
mi:= msp mod 60; msp:= msp div 60;
he:= msp mod 60; s:='';
if Duree<=1000 then Format:=3;
case format of
1 : begin
if he<>0 then s:=s+intToStr(he)+'h ';
if mi<>0 then s:=s+intToStr(mi)+'m ';
if se<>0 then s:=s+intToStr(se)+'s ';
s:=s+intToStr(ms)+'ms';
end;
2 : begin
t:=intToStr(he); s:=s+t+':'; //12:15:04:045
t:=intToStr(mi); t:=calibre(t,2); s:=s+t+':';
t:=intToStr(se); t:=calibre(t,2); s:=s+t+':';
t:=intToStr(ms); t:=calibre(t,3); s:=s+t;
end;
3 : s:=intToStr(Duree)+' ms';
end;
Mis:=s;
end; |
Partager