HOME - - / - - / - -
LAZARUS/ DELPHI TUTORIALS
LAZARUS/ DELPHI COURSE - - / - - / - -
Other material for programmers
Lazarus and Delphi Course: First Essay (Short!): Events and Multitasking
Page URL: EssEven.htm
This page is information rich, and a has search button at the bottom of the page.
Please don't dismiss it because it isn't full of graphics, scripts, cookies, etc!
You will probably find the text easier to read if you make your browser window much narrower than usual. You may also want to change your browser's zoom level, to enlarge the text. Opera (at least) lets you change zoom level easily. The text will adapt nicely to the settings you decide give the best results for your needs!
The lines of sample Lazarus/ Delphi code in these pages will not "wrap". I.e., if a line is too long to show in the width you have set your browser too, parts of the line will be "off the page". Those lines will still copy/paste properly, at least in Opera. Please feel free to send feedback on the choices I've made! (Will you forgive me for not forcing upon you a column of links on the left and a column of ads on the right?)
This is just one exercise in a series of Lazarus / Delphi exercises. You will probably be best served by doing them in sequence... each assumes some prior knowledge. Material © TK Boyd, sheepdogsoftware.co.uk, 4/05-6/20.
Heavily re-worked, June 2020, to bring it up to date for Windows 10/ Lazarus 2.0.0 Based on earlier Delphi page. Probably still useful to Delphi programmers, too.
Almost all of this course will be taught using lots of hands-on examples. Some things, however, just have to be dealt with the "boring" way. Eat your vegatables. Read the essays. Mother will be pleased. You will progress faster.
Pascal is the language behind the two IDEs, "Lazarus" and "Delphi". The IDSs are for writing programs to run under Windows and other modern operating systems. If you, like me, are fed up with the Windows monopoly abuse, and the direction Mr.Gates seems to be going, you may be considering making the move to Linux. If you do... or if you like the Mac... I am told that Lazarus also works just fine on both.
Even if you do go to Linux, you will find there, as in Windows, that you are working in a multitasking, event driven environment.
This is Good because you can do clever things relatively easily. This is Bad because you can do nothing as easily as you could do it back in the bad old, limited old, days of mono-tasked systems with no events.
In the old days, a computer would be doing almost nothing apart from what your application specified. This made getting things to work quite easy. It also meant you could only do one thing at a time.
The computer I'm working on at the moment is "doing" six obvious things, and many more under the surface. For example, even as I am typing this, there is an open connection to the internet. That is being guarded by a software firewall. In the lower right of the screen, a clock is displayed, telling me the time. Etc, etc.
I've just ben talking about multi-tasking. I haven't gone into much depth, but you don't need it yet.
More important to you just now is the concept and use of events.
In the applications we've done so far, we've used a button's OnClick event and an edit box's OnChange event.
Think back to the Inches to Centimeters converter application. You didn't write any code in that to say "Watch to see if the user is typing something into the edit box"... and yet, when the user did that, things happened. If you added a "Quit" button to the application, again: you didn't write any "See if the user has the mouse pointer over the quit button, has clicked the mouse" code. All of these things are taken care of for you by Windows (or Linux). The changing of the edit box contents, the clicking of the mouse on the virtual button generate "events". The events travel through the various things which are going on, and, if appropriate, the event handling code in your application is executed whenever the event arises. Pretty cool! A little strange, at first, but if you don't think about it too hard, you'll soon be using it with little difficulty.
If all that's clear, stop reading here.
I guess it wasn't clear?
If you come from the "old school", the following may help.
In the old days, we could write something like:
Get first number
Get second number
Output the sum of the two numbers
Get a key
Until the key was "Q"
Do any shut down things
In those days, the application and the computer would stop and wait patiently at places like "Get a key". In those days, with the program above, you had to give the computer the first number first. You had to supply the second number before you could quit.
A comparable application today would have two edit boxes (for "first number" and "second number". They could be entered in either order. There would be a label in which the sum of the numbers would appear. There would be a button to terminate the application. It could be clicked before any numbers had been entered.
It may help... or may confuse... to think of a Windows computer along the following lines....
Initialise computer, during power on
If an application is requested, start it up
See if event 1 has occured. If so, set flag
See if event 2 has occured. If so, set flag
See if event 3 has occured. If so, set flag
See if event 4, 5, 6 etc... has occured. If so, set flag
For each running application, see if they are interested in
any of the flags which have been set by the
various events. If so, the applications can change their
states, as necessary
Until computer is told to shut itself down
Do any shut down things
It isn't really quite that simple... but that model will suffice for now!
A useful point arises even from such a crude model. A moment ago, I described a possible application, the one with two edit boxes. They would probably each have their own OnChange event handler. In other circumstances, it is useful (and allowed) to have several components all share one bit of code to handle some event.
Search just this site without using forms,
Or... again to search just this site, use...
The search engine 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", "get" and "rich".
I have other sites...
My site at Arunet.
Ad from page's editor: Yes.. I do enjoy compiling these things for you... I hope they are helpful. However.. they don't pay my bills!!! If you find this stuff useful, (and you run an MS-DOS or Windows PC) please visit my freeware and shareware page, download something, and circulate it for me? Links on your page to this page would also be appreciated.
Click here to visit editor's Sheepdog Software freeware, shareware page.
Link to Tutorials main page
Link to Lazarus/ Delphi Course index
To email this page's editor, Tom Boyd....
Editor's email address. Suggestions welcomed! Please cite "EssEven.htm".
Page has been tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org. Mostly passes.
One final suggestion: Be sure you know all you need to about spyware.
. . . . . P a g e . . . E n d s . . . . .