大家来看看这段代码,奇怪了,真奇怪。。。 ( 积分: 100 )

  • 主题发起人 主题发起人 nanshan
  • 开始时间 开始时间
N

nanshan

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure&nbsp;TForm_dingshi.TimerTimer(Sender:&nbsp;TObject);<br>var<br>&nbsp;&nbsp;i:&nbsp;integer;<br>&nbsp;&nbsp;runtime,ntime:&nbsp;Tdatetime;<br>&nbsp;&nbsp;sm:string;<br>begin<br>&nbsp;&nbsp;if&nbsp;ListViewbusy&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;Exit;<br>&nbsp;&nbsp;Label2.Caption&nbsp;:=&nbsp;'当前时间:'&nbsp;+&nbsp;DateTimeToStr(Now);<br>&nbsp;&nbsp;for&nbsp;i&nbsp;:=&nbsp;0&nbsp;to&nbsp;ListView1.Items.Count&nbsp;-&nbsp;1&nbsp;do<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;runtime&nbsp;:=&nbsp;StrToDateTime(ListView1.Items.SubItems.Strings[0]);<br>&nbsp;&nbsp;&nbsp;&nbsp;ntime&nbsp;:=&nbsp;Now;<br>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;SecondsBetween(runtime,&nbsp;ntime)&nbsp;=0&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Form_main.LoadfileTimeliat;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sm:=&nbsp;ListView1.Items.SubItems.Strings[2];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ShellExecute(Application.handle,&nbsp;'open',&nbsp;PChar(sm),&nbsp;nil,&nbsp;nil,&nbsp;SW_ShowNormal);///就是这句话,执行一次打开两次文件。<br>&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;end;<br>end;<br><br>如果用时间控件触发就会执行一次,工作两次。<br><br>procedure&nbsp;TForm_dingshi.Button2Click(Sender:&nbsp;TObject);<br>var<br>&nbsp;&nbsp;i:&nbsp;integer;<br>&nbsp;&nbsp;runtime,ntime:&nbsp;Tdatetime;<br>&nbsp;&nbsp;sm:string;<br>begin<br>&nbsp;&nbsp;Label2.Caption&nbsp;:=&nbsp;'当前时间:'&nbsp;+&nbsp;DateTimeToStr(Now);<br>&nbsp;&nbsp;for&nbsp;i&nbsp;:=&nbsp;0&nbsp;to&nbsp;ListView1.Items.Count&nbsp;-&nbsp;1&nbsp;do<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;runtime&nbsp;:=&nbsp;StrToDateTime(ListView1.Items.SubItems.Strings[0]);<br>&nbsp;&nbsp;&nbsp;&nbsp;ntime&nbsp;:=&nbsp;Now;<br>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;SecondsBetween(runtime,&nbsp;ntime)&nbsp;=0&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Form_main.LoadfileTimeliat;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sm:=&nbsp;ListView1.Items.SubItems.Strings[2];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ShellExecute(Application.handle,&nbsp;'open',&nbsp;PChar(sm),&nbsp;nil,&nbsp;nil,&nbsp;SW_ShowNormal);<br>&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;end;<br>end;<br><br>这样放到按钮下就可以执行一次打开一次了。<br><br>我保证时间控件是执行了一次却打开文件两次。<br>高手帮忙看看呀。实在是糊涂了。
 
ShellExecute(Application.handle,&nbsp;'open',&nbsp;PChar(sm),&nbsp;nil,&nbsp;nil,&nbsp;SW_ShowNormal);///就是这句话,执行一次打开两次文件。<br>在这句后面加一条语句:ListViewbusy&nbsp;:=&nbsp;true;
 
procedure&nbsp;TForm_dingshi.TimerTimer(Sender:&nbsp;TObject);<br>var<br>&nbsp;&nbsp;i:&nbsp;integer;<br>&nbsp;&nbsp;runtime,ntime:&nbsp;Tdatetime;<br>&nbsp;&nbsp;sm:string;<br>begin<br>&nbsp;&nbsp;if&nbsp;ListViewbusy&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;Exit;<br>&nbsp;&nbsp;Label2.Caption&nbsp;:=&nbsp;'当前时间:'&nbsp;+&nbsp;DateTimeToStr(Now);<br>&nbsp;&nbsp;for&nbsp;i&nbsp;:=&nbsp;0&nbsp;to&nbsp;ListView1.Items.Count&nbsp;-&nbsp;1&nbsp;do<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;runtime&nbsp;:=&nbsp;StrToDateTime(ListView1.Items.SubItems.Strings[0]);<br>&nbsp;&nbsp;&nbsp;&nbsp;ntime&nbsp;:=&nbsp;Now;<br>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;SecondsBetween(runtime,&nbsp;ntime)&nbsp;=0&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Form_main.LoadfileTimeliat;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sm:=&nbsp;ListView1.Items.SubItems.Strings[2];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ShellExecute(Application.handle,&nbsp;'open',&nbsp;PChar(sm),&nbsp;nil,&nbsp;nil,&nbsp;SW_ShowNormal);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[red]&nbsp;Exit;[/red]<br>&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;end;<br>end;
 
procedure&nbsp;TForm_dingshi.TimerTimer(Sender:&nbsp;TObject);<br>var<br>&nbsp;&nbsp;i:&nbsp;integer;<br>&nbsp;&nbsp;runtime,ntime:&nbsp;Tdatetime;<br>&nbsp;&nbsp;sm:string;<br>begin<br>&nbsp;&nbsp;if&nbsp;ListViewbusy&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;Exit<br>&nbsp;&nbsp;else&nbsp;begin<br>&nbsp;&nbsp;&nbsp;Label2.Caption&nbsp;:=&nbsp;'当前时间:'&nbsp;+&nbsp;DateTimeToStr(Now);<br>&nbsp;&nbsp;for&nbsp;i&nbsp;:=&nbsp;0&nbsp;to&nbsp;ListView1.Items.Count&nbsp;-&nbsp;1&nbsp;do<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;runtime&nbsp;:=&nbsp;StrToDateTime(ListView1.Items.SubItems.Strings[0]);<br>&nbsp;&nbsp;&nbsp;&nbsp;ntime&nbsp;:=&nbsp;Now;<br>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;SecondsBetween(runtime,&nbsp;ntime)&nbsp;=0&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Form_main.LoadfileTimeliat;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sm:=&nbsp;ListView1.Items.SubItems.Strings[2];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ShellExecute(Application.handle,&nbsp;'open',&nbsp;PChar(sm),&nbsp;nil,&nbsp;nil,&nbsp;SW_ShowNormal);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit;<br>&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;end;<br>&nbsp;&nbsp;end;<br>end;
 
SecondsBetween(runtime,&nbsp;ntime)&nbsp;=0<br>解决了,就是这个句话,换了就好了
 
路过帮顶!!1
 
多人接受答案了。
 
后退
顶部