(Ebook - Pdf) Kick Ass Delphi Programming
.pdfIt was helpful to dig into the source code for the TApplication object, to see just how messages were processed by default, and how any OnMessage event handler I might create should participate in the overall process. Specifically, what should I do (if anything) with the Handled variable passed to the event handler? Listing 12.9 reveals the source for the TApplication’s ProcessMessage method, which is called as part of any application’s endless message processing loop.
Listing 12.9 Source code for TApplication’s ProcessMessage method
function TApplication.ProcessMessage: Boolean; var
Handled: Boolean; Msg: TMsg;
begin
Result := False;
if PeekMessage(Msg, 0, 0, 0, PM_REMOVE) then begin
Result := True;
if Msg.Message <> WM_QUIT then begin
Handled := False;
if Assigned(FOnMessage) then FOnMessage(Msg, Handled);
if not IsHintMsg(Msg) and not Handled and not IsMDIMsg(Msg) and not IsKeyMsg(Msg) and not IsDlgMsg(Msg) then
begin TranslateMessage(Msg); DispatchMessage(Msg);
end; end else
FTerminate := True;
end;
end;
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.
With my newly found programming knowledge I’ll rule the world! Ha ha ha ha!....”
The fit of uncontrolled laughter lasted for nearly ten minutes. Then the Avenger opened a fresh pack of HoHos and smugly turned to the next page.
Some Sound Advice
Casebook No. 16, March 22: Today, I discovered how to play a .WAV file from my Delphi applications. Not that it’s at all difficult. But I was thinking how great it would be to have one of my biggest heroes—Humphrey Bogart—speak when I clicked a button in an application.
Figure 12.6 shows an executing version of the form I created to test my experiments. Listing 12.10 contains the code.
FIGURE 12.6 Ace’s WAV form.
Listing 12.10 A demo program that plays .WAV files
{———————————————————————————————————————————————————}
{ |
The .WAV File Player Demo |
} |
{ |
PLAYMAIN.PAS : Main Unit |
} |
{ |
By Ace Breakpoint, N.T.P. |
} |
{ |
Assisted by Don Taylor |
} |
{ |
|
} |
{ Application that demonstrates how to play a .WAV |
} |
|
{ file in a Delphi application. |
} |
|
{ |
|
} |
{ Written for *Kick-Ass Delphi Programming* |
} |
|
{ Copyright (c) 1996 The Coriolis Group, Inc. |
} |
|
{ |
Last Updated 3/22/96 |
} |
{———————————————————————————————————————————————————}
unit playmain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, MMSystem;
type
TForm1 = class(TForm) BadgeBtn: TButton; ExitBtn: TButton;
procedure BadgeBtnClick(Sender: TObject); procedure ExitBtnClick(Sender: TObject);
private
{Private declarations } public
{Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.BadgeBtnClick(Sender: TObject); begin
if not PlaySound('badges.wav', 0, SND_FILENAME)
then MessageDlg('Problem playing sound file', mtError, [mbOK], 0);
end;
procedure TForm1.ExitBtnClick(Sender: TObject); begin
Close;
end;
end.
At first, I had assumed I would have to use a MediaPlayer component to play a file. I soon discovered an alternative low-level function called PlaySound in the MMSystem unit. I simply gave it the name of the file and the constant SND_FILENAME, which indicated I wanted the routine to play a sound stored in a file. It doesn’t get much easier than that.
Note to myself: The file used for my experiment (BADGES.WAV) is an edited excerpt from the famous “Stinking Badges” dialog in the classic 1948 Bogie movie, “The Treasure of the Sierra Madre.” It’s one of my faves.
End of entry, March 22.
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.
conversation earlier that morning with Marge Reynolds.
“So at least we have a fairly good description of the perpetrator,” he concluded. “I’m just not sure it leads anywhere. We left a note on the Manager’s door, asking him to call when he returns.”
“Don’t you see?” Helen asked incredulously. “It’s got to be Melvin Bohacker. The description fits. I’m sure he is just being vindictive about what happened in The Case of the Duplicitous Demo, and he’s trying to get back at both of us. He probably hired that woman to make the bogus phone call for him. I’ll bet he’s sitting at home right now, gloating over the whole situation.”
“I don’t think it’s that simple, Helen,” Ace replied. “You didn’t see Bohacker’s face when I—”
Ace’s attention had been grabbed by something outside. Through the blinds in the side window, he could make out the shape of a man moving about in the bushes. He was a tallish man, wearing a brimmed hat and a long, khaki-colored raincoat. He moved closer to the window and peered inside.
“That’s him!” Ace shouted. “That’s the man Marge described, and undoubtedly the man who stole my Casebook. He has returned, just as sure as another sequel to Nightmare on Elm Street—and I’ve got some very pointed questions to ask him!”
The intruder’s eyes shot wide open when Ace cried out, but as soon as Ace moved toward the door, the mysterious stranger bolted from the shrubbery, heading diagonally across the parking lot. Ace followed in hot pursuit, hampered greatly by the slippery mud that now completely covered the asphalt.
“Stop!” Ace commanded. But the raincoated figure just scrambled faster. Ace managed to give an extra surge, catching up with the stranger and tackling him in front of the Manager’s office. The tall interloper hit the ground hard, letting out a loud groan. Together, they slid a full six feet in the mud before coming to a stop.
“Hey—what’s goin’ on here?” came a voice from behind. Ace wrenched his head around far enough to see Marvin Gardens, the property manager, walking up behind him.
“I’ve caught the intruder Marge saw last night,” Ace replied, vainly trying to keep the rain out of his eyes. “The guy who lifted my Casebook.” With some effort, Ace managed to stand up, still maintaining an iron grip on the man in the raincoat. Both men were covered with mud from head to toe.
“Yeah, I got yer note,” said Gardens, chewing on the stogie clamped between his crooked, yellow teeth. “I was gonna call ya. But dis is no intruder, Breakpoint. Say ‘Hello’ ta my new groundskeeper, Sergei Stakupopov. He don’t speak much English, but dat much he’ll understand.”
“Wait a second,” Ace protested. “Last night this man was seen holding some kind of weapon. He was confronted twice, and each time he ran away. Gardener or not, that says he’s guilty.”
“Where he’s from, people live in fear of da secret police,” Gardens replied, after taking a puff off the cheap stogie. “In his country, a challenge yelled by someone could be da last thing ya ever hear. He’s here onna Green Card, and he’s deathly afraid he’s gonna lose it, which would mean his family would have ta return to da homeland. That’s why he’s willing ta work long, hard hours. He was trimmin’ da bushes by your apartment last night—Marge probably saw him holdin’ a pairra shears, dat’s all.”
Ace loosened his grip on the immigrant, then sheepishly shook hands with the groundskeeper and apologized profusely. Sergei watched him guardedly, then smiled politely and said “Hello.”
The former P.I. trudged back to his office, where Helen was waiting with a million questions. He related his experiences of the past few minutes, then just stood there, hanging his head.
“Hey, it’s going to be okay,” Helen affirmed once again. “This is just a temporary setback. Now get out of that muddy trenchcoat before you catch a cold.”
Reluctantly, Ace complied. “I wish I could believe it’s only temporary,” he said, choosing a fresh trenchcoat and hat from the row of identical outfits in his closet.
“Of course it is, Sweetheart,” she replied. “Listen, my lunch hour is over, and I’ve got to get back to the shop. But give me a call this afternoon. I’ll stop by after work, to see how things are going.”
She gave him a kiss on the cheek and then slipped out into the pouring rain.
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.