如何在DELPHI中实现EDIT1中显示当前精确到微秒的字串呀?多谢啦!分分! (20分)

  • 主题发起人 lovelyman
  • 开始时间
L

lovelyman

Unregistered / Unconfirmed
GUEST, unregistred user!
如何在DELPHI中实现EDIT1中显示当前精确到微秒的字串呀?多谢啦!分分!
 
我的邮件地址为fair@army.com
 
这个是不是这样?
在form中放一个Timer控件,每毫秒给edit赋一次值。
edit1.text := formatdatatime(now, 'yyyy:mm:dd:hh:nn:ss zzz');
 
edit1.text := FormatDateTime('yyyy:mm:dd:hh:nn:ss zzz',now);
 
Timer.Interval最小只能为55(毫秒)!
但这里要求的是微妙级!
 
以上的几位都做到了毫秒级的功能,但是还离微秒隔好多呀![:)]
 
呵呵,那你就换用精确的记时控件吧
 
有实现上面我功能的控件吗?

有的话,在什么地方有的下呀,给我一个下的地址吧!如果成功,立马给分!

但我总感到实现这个功能不至于要用到第三方的东东!

当然实在没有办法了,用一下三方也无关系!
[:)]
 
好象不是太简单哦。。。
http://www.aogosoft.com/bbs/mixpage.asp?mode=viewoktext&fileid=54
 
能不能给出具体实现:(USE PASCAL SOURCE)
EDIT1中显示当前时间精确到微秒的字串


上面的一文章我看了一上,用CPP的;
多谢各位啦!
[:)]

 
难道大富翁上没有一人能写出实现上面的功能的代码来?

有的话,贴上来共同研一下吧!

YAHOO MESSENGER:lovelyman_gold@yahoo.com.cn


[:)]

 
说明:
button1:开始计时,button2:结束计时

结果:Now时间好像只能精确到17毫秒,
所以如果f:=Now这句能够取到更精确的值就好了。

//-----------------------------------------------------
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
bGoOn:boolean;
lastS:string;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
f:Double;
s:string;
begin
bGoOn:=true;
while bGoOn do
begin
f:= now;
s:=FormatDateTime('yyyy:mm:dd:hh:nn:ss:zzz',f);
f:=f*24*3600*1000;
f:=f - Integer(Trunc(f));
s:=s+':'+inttostr(integer(trunc(f*1000)));
if s <> lastS then
begin
ListBox1.Items.Add(s);
lastS:=s;
end;
Application.ProcessMessages;
end;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
bGoOn:=false;
end;

end.
 
//以下差不多精确到22微秒

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,Math, ExtCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
bGoOn:boolean;
MMSecLong:integer;
lastS:string;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
function cyclecount:int64;
asm
db $0f
db $31
end;

procedure TForm1.Button1Click(Sender: TObject);
var
f:Double;
s:string;
a,c,d,iStart,iDiv:int64;
year,Month,Day,Hour,Min,Sec,Msec,MMsec:word;
begin
c := cyclecount;
sleep(100);
d := cyclecount;

//平均每微秒的周期,奇怪的是用10毫秒、100毫秒和1000毫秒得到的结果差很大
MMSecLong:=(d-c) div (100*1000);

f:= now;
iStart:= cyclecount;
DecodeDate(f,year,Month,Day);
DecodeTime(f,hour,min,sec,msec);
MMsec:=0;
a:=0;
bGoOn:=true;
while bGoOn do
begin
iDiv:= cyclecount ;

MMSec:=MMsec+(iDiv-iStart) div MMSecLong;
iStart:=iDiv;

MSec:= MSec + MMSec div 1000;
MMsec:=MMsec mod 1000;

Sec:= Sec + MSec div 1000;
MSec:=Msec Mod 1000;

Min:=Min+(Sec div 60);
Sec:= sec mod 60;

Hour:=Hour+(Min div 60);
Min:= Min mod 60;

if Hour > 24 then
begin
//重新调用比计算天数简单吧
Button1Click(nil);
exit;
end;
s:=Format('%d-%d-%d %d:%d:%d %d %d',[year,month,day,hour,min,sec,Msec,MMsec]);
if s <> lastS then
begin
ListBox1.Items.Add(s);
lastS:=s;
end;
a:=a+1;
if a > 2000 then
begin
Application.ProcessMessages;
a:=0;
end;
end;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
bGoOn:=false;
end;

end.
 
功能还没有实现,但时间好长了,要结帖啦!
我也不想在这一问题上花的时间太多了。
多谢各位啦!

如果找到了确可以实现上面功能的代码,发给我好吗?
You could send it to "fair@army.com"
or send to yahoo messenger:"lovelyman_gold@yahoo.com.cn".
Thanks!
 
多人接受答案了。
 
顶部