求助,delphi中如何实现这种功能?(100分)

  • 主题发起人 主题发起人 hjy2000
  • 开始时间 开始时间
H

hjy2000

Unregistered / Unconfirmed
GUEST, unregistred user!
当程序运行,主FORM出现后,<br>1。在一定时间中无用户干预(如单单击等)情况下自动执行一段代码??<br>2。在一定时间中有用户干预(如单单击等)情况下执行另一段代码,如参数设定等<br>&nbsp; 要求不用TIMER控件<br>请问如何实现?<br>谢谢<br>
 
有一个TONIDEL**的控件可以,:>
 
可以用一个延时程序吗?
 
问题是 1 如何实现?
 
可以建立一个ActionList控件,在其中添加一个Action,添加它的OnUpdate回调完成空闲处理。
 
form1create事件里加延时程序也可以解问吧!<br>就看延时多久就是了!
 
to:yt_wyb<br>&nbsp; 能解释细些吗? 给些代码。谢谢<br>to:zdb123<br>&gt;主FORM出现后<br>不要在form1create事件中处理
 
OnIdle 不行么?
 
无聊,Timer为什么不好?用线程?
 
使用TApplicationEven 的OnIdle事件处理:<br>Occurs when an application becomes idle.<br>type TIdleEvent = procedure (Sender: TObject; var Done: Boolean) of object;<br>property OnIdle: TIdleEvent;<br>Description<br>Write an OnIdle event handler to perform special processing when an application is idle. An application is idle when it is not processing code. For example, an application is idle when it is waiting for input from the user.<br>TIdleEvent has a Boolean parameter Done that is True by default. When Done is True, the Windows API WaitMessage function is called after OnIdle returns. WaitMessage yields control to other applications until a new message appears in the message queue of the application. When Done is False, the application does not yield control to other applications while it is not busy.<br>OnIdle is called only once, as the application transitions into an idle state. It is not called continuously unless Done is set to False. Applications that set Done to False consume an inordinate amount of CPU time, which affects overall system performance.<br><br>Note: Call the CancelDispatch method from an OnIdle event handler to prevent the application from forwarding the event to any other application events objects.
 
不防償試一下我的方法:<br>&nbsp;private<br>&nbsp; &nbsp; Procedure zxb(Sender: TObject; var Done: Boolean);//自定義過程聲明<br><br>var index1:integer=0;<br>&nbsp; &nbsp; flag:boolean=false;<br>&nbsp; &nbsp; time1:integer;<br>Procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp;time1:=1000;//需要等待的時間<br>&nbsp;application.OnIdle:=zxb;<br>end;<br><br>Procedure tform1.zxb(Sender: TObject; var Done: Boolean);<br>begin<br>&nbsp;if index1=0 then<br>&nbsp; begin<br>&nbsp; &nbsp;sleep(time1); &nbsp;//等待設定的時間<br>&nbsp; &nbsp;index1:=1<br>&nbsp; end<br>&nbsp;else<br>&nbsp; if index1=1 then<br>&nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp;index1:=2;<br>&nbsp; &nbsp; &nbsp;if flag then<br>&nbsp; &nbsp; &nbsp; showmessage('有用戶干撓!') //在此可寫要執行的代碼<br>&nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; if not flag then<br>&nbsp; &nbsp; &nbsp; &nbsp; showmessage('無用戶干撓!');//在此可寫要執行的代碼<br>&nbsp; &nbsp; end;<br>end;<br><br>procedure TForm1.FormClick(Sender: TObject);<br>begin<br>&nbsp;flag:=true; &nbsp;//有用戶干預,將flag變為True.<br>end;<br>
 
后退
顶部