This is one of my tutorials where most of the goodness is in the sourcecode.
You can download it.. (That gives you the whole Lazarus project. Assuming you have the Lazarus IDE installed, just unzip the download, dbl click in the .lpi file.)
Alternatively, you can open the .pas file to see the code, and the supporting comments....
OR!... if that doesn't appeal, you can double-click on the .exe file, to see the demo on action... but be advised, that doesn't do anything clever. It is just a simple demo of using a control loop to structure an app's behavior.
Oh... by the way... along the way, I've given you a "boilerplate" with many elements that I find it useful to incorporate in almost every app I write. Including the code to manage an ini file, so the app remembers where you had it on your screen, and what size.
Some apps are not heavily dependant on user input. Sensor monitoring, process control, etc are examples of useful programs that are meant to "just get on with it".
The demo could be a useful "template" for you. Written to BE a "template", to be something that new apps can be built on, just by "plugging in" subroutines.
Give it a try? Read the comments in the sourcecode?
It is set up to go "round and round" the loop that is the heart of it at a steady tempo. Each complete pass through the cycle should take about the same time.
This is not the only possibility.
What follows will make more sense when you've studied the code a bit!
Instead of "timing" the "ticking" of the "do next think" clock with a TTimer object, you can tweak that by setting the TTimer object's enabled property to "false" as you enter one of the subroutines called from the loop. Just be sure to put it back to "true" as you exit the subroutine.
Or, you can take the TTimer out entirely. If you do that, make a copy of what is currently the TTimer's timeout event a subroutine itself. Call it "DoIt".
Create a button to start things off, and make its OnClick handler...
repeat DoIt; until false;
As I said at the start: There's not much in this webpage. But if you fetch and study the sourcecode I spent days getting "nice" for you, I think you will be glad of what you can learn from that.
Usually my pages "talk" much more than this one does. Do you like this "just give us the code" alternative?
Please get in touch if you discover flaws in this page. Please mention the page's URL. (wywtk.com/lut/ldn149coreloop/ldn149.htm).
If you found this of interest, please mention in forums, give it a Facebook "like", Google "Plus", or whatever. If you want more of this stuff, help!? There's not much point in me writing these things, if no one feels they are of any use.
Unlike the clever Google search engine, this one merely looks for the words you type, so....
* Spell them properly.
* Don't bother with "How do I get rich?" That will merely return pages with "how", "do", "I"....
Please also note that I have three other sites, and that this search will not include them. They have their own search buttons.
My SheepdogSoftware.co.uk site, where you'll find my main homepage. It has links for other areas, such as education, programming, investing.
My SheepdogGuides.com site.
My site at Arunet.
Page has been tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org. It passes in some important ways, but still needs work to fully meet HTML 5 expectations. (If your browser hides your history, you may have to put the page's URL into the validator by hand. Check what page the validator looked at before becoming alarmed by a "not found" or "wrong doctype".)
....... P a g e . . . E n d s .....