开发者

Make application With timers etc.? [closed]

It's difficult to tell what is being asked开发者_JAVA技巧 here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I need to make an application as followed.

A query needs to be executed 10 times a second to check in the database (Ms SQL 2005) if the value of the field is 1 or 0. if its 1 then the appication needs to start Windows Media Player (Fullscreen) and run a video. The application needs to sleep during the video and when the video is finished the application needs to awake and close Windows Media Player and open Internet Explorer(fullscreen) and show a website.

I have no idea how to make this im not that experienced with Delphi.


Drop a TTimer onto a Delphi form. Set the timer's interval property to 100 (measured in milli-seconds). Assign an event handler for the OnTimer event that checks your database. Set the Enabled property to False.

When you want the timer to start firing events set Enabled to True. When you want it disabled, set Enabled back to False.

One thing to be careful of is if your timer event handler takes more time to run than the timer interval. If that happens then there will be no pause in between invocations of the handler. This won't do any terrible harm, but it may result in your app consuming 100% CPU. A defensive technique is to set the timer's Enabled property to False at the beginning of your event handler, and then back to True just before you exit the handler.


Re-reading your question, it occurs to me that perhaps you are asking how to do the database access, starting Media Player, sleeping during the video, waiting for it finish, opening IE etc.

You can't ask how to do all of that in one question (please see the FAQ for a description of what is a valid question on Stack Overflow). If you really want answers to all of that then we'll just close the question as being too broad.

My answer above gives you some orientation for the timer part of your question.


If you don't require a delphi form application you could do this with a server-side web page (php, asp.net, jsp whatever's your favorite).

  • Inital page load (server side) would check your database (1 or 0)?

  • Client side page would refresh every n sec.

  • ... or play video and redirect to website

  • Website redirects to Inital page after n sec.

If you can't control the website you need to display you could call it inside a frame.


Instead of polling that record continuosly, I'd use a trigger to tell my application when the values has changed - of course if you can add such a trigger to the database.

If you can't add a trigger, I'd use a separate thread to check for the field change (use a proper query prepared with bind variables to avoid statement reparsing overhead). The thread can be put to sleep while the application plays the video - check what's the best way to run Media Player (embedded or not), because you need to know when it has finished playing, and I do not know if it is easy to obtain that information if Media Player is run as an external application using ShellExecute or CreateProcess, while it is easy enough to run an external application and wait for it to terminate.

Opening Explorer is just a matter of calling ShellExecute (or CreateProcess) with the right parameters.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜