[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppWindows » QbasicFAQ_WinVista » CppOop » QbasicFAQ_PlayAndSound » BeginnersGuideToJavaScript » How_To_Javascript_Show_Hide_Elements_On_Button_Click » J2MEFAQ » CurlHistory » CHelloWorld » QuickHelp » Intro-EDP
More Good News: If you know just a little bit, all sorts of useful things become really easy.
This is off the top of my head, not rigourously tested... apologies for little boo-boos. Tests for the student? And as this is a wiki, anyone who knows better, feel free to pitch in and tidy things up. I won't be offended! Don't look for "Why would I want this?" You wouldn't. But it illustrates EDP!
Trivial example:
Via EDP, it is really really easy to accomplish the following:
I'm going to have a form with two labels on it. Normally, the lettering on them will be the usual label text color. Move the mouse over them, and the writing will turn green.
Start the project; put the labels on it.
Get the Object Inspector visible (F11). Click on the first label. Click on the "Events" tab of the object inspector. Doubleclick in the empty cell to the right of "OnMouseMove". That will create the shell of....
Between the "begin" and "end", add "Label1.Font.Color:=clGreen;
Run the program. When you move the mouse pointer over the label, the text of the label will go green! Whee! (Once that's working, repeat the process for the other label.) (Sadly, making the color go back to the normal color when the mouse LEAVES the label is a longer story. Come on, fellow Codepedians... someone else can write up that bit! Please put on separate page, linked to from here?)
But! Trivial as the example is, if you think about it, you should be impressed. YOU didn't have to write any code to tell Windows to keep an eye on where the mouse pointer was, where the label is, and to execute Label1MouseMove... with whatever code you chose to put in it... when the pointer moved over the label.
One of those things that "everybody knows" (and forgets to tell novices!!) is that EACH label (indeed most "things" on a form) has its OWN MouseMove "event handler".... i.e. the code to be executed, the code for handling, the event whenever it arises. (In the simple, beginner's example, we used two handlers, one for each lael's MouseMove event. It IS possible to write just one copy of the handler, and have it "shared" between the labels. Such a shared handler can even turn the text of just one of the labels... the correct one!... a different color.)(Another troll for someone to add a connected page with the details!)
If you want more help with Delphi programming, I've written pages and pages of stuff, all accessible via the table of contents at....
http://sheepdogguides.com/tut.htm
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppWindows » QbasicFAQ_WinVista » CppOop » QbasicFAQ_PlayAndSound » BeginnersGuideToJavaScript » How_To_Javascript_Show_Hide_Elements_On_Button_Click » J2MEFAQ » CurlHistory » CHelloWorld » QuickHelp » Intro-EDP
(Delphi) Event driven programming
First the Good News: You don't NEED to know much about "Event Driven Programming". (I'm not sure that "EDP" is a widely used acronym, but I'm going to use it here, and save my fingers.)More Good News: If you know just a little bit, all sorts of useful things become really easy.
==
A "trivial" exampleThis is off the top of my head, not rigourously tested... apologies for little boo-boos. Tests for the student? And as this is a wiki, anyone who knows better, feel free to pitch in and tidy things up. I won't be offended! Don't look for "Why would I want this?" You wouldn't. But it illustrates EDP!
Trivial example:
Via EDP, it is really really easy to accomplish the following:
I'm going to have a form with two labels on it. Normally, the lettering on them will be the usual label text color. Move the mouse over them, and the writing will turn green.
Start the project; put the labels on it.
Get the Object Inspector visible (F11). Click on the first label. Click on the "Events" tab of the object inspector. Doubleclick in the empty cell to the right of "OnMouseMove". That will create the shell of....
procedure TForm1.Label1MouseMove...
Between the "begin" and "end", add "Label1.Font.Color:=clGreen;
Run the program. When you move the mouse pointer over the label, the text of the label will go green! Whee! (Once that's working, repeat the process for the other label.) (Sadly, making the color go back to the normal color when the mouse LEAVES the label is a longer story. Come on, fellow Codepedians... someone else can write up that bit! Please put on separate page, linked to from here?)
But! Trivial as the example is, if you think about it, you should be impressed. YOU didn't have to write any code to tell Windows to keep an eye on where the mouse pointer was, where the label is, and to execute Label1MouseMove... with whatever code you chose to put in it... when the pointer moved over the label.
One of those things that "everybody knows" (and forgets to tell novices!!) is that EACH label (indeed most "things" on a form) has its OWN MouseMove "event handler".... i.e. the code to be executed, the code for handling, the event whenever it arises. (In the simple, beginner's example, we used two handlers, one for each lael's MouseMove event. It IS possible to write just one copy of the handler, and have it "shared" between the labels. Such a shared handler can even turn the text of just one of the labels... the correct one!... a different color.)(Another troll for someone to add a connected page with the details!)
=
A little mystery: When, using Delphi 2 & Win 98, I tried to do almost the same thing, but using buttons instead of labels, I couldn't get the color of the button's caption to change. Sigh.=
One event you will use a lot is the OnClick handler for buttons. The Onchange of Edit Boxes can be useful, too... but using it can be a bit tricky to gt right! (It is easy to try to change what is in the box in some situations, the change itself triggering another "Handle-OnChange...", etc.)=
The Help File entries for every component list the component's properties, which I suspect you know. It also lists the built-in events for that component. Browse those parts of the Help File, and you will soon see other useful events.=
Once you are past the "beginner" level, I believe you can even add new events to the system... not that I've felt the need yet!=
Now then... I'm new to Codepedia... if some senior editor wants to remove the following, I won't be too upset... but please do not remove it unless you are really, really sure that "everyone" at Codepedia has agreed that such links aren't allowed. No on has to click it, after all! And I'm not (here/ there) selling anyting....If you want more help with Delphi programming, I've written pages and pages of stuff, all accessible via the table of contents at....
http://sheepdogguides.com/tut.htm
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
