Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

(Ebook - Pdf) Kick Ass Delphi Programming

.pdf
Скачиваний:
284
Добавлен:
17.08.2013
Размер:
5.02 Mб
Скачать

OneCombo: TComboBox; Panel1: TPanel; Label1: TLabel; NumRcvrsLabel: TLabel; Bevel1: TBevel; Bevel2: TBevel; Label2: TLabel; StatusLabel: TLabel; StatusTimer: TTimer; MsgGroup: TGroupBox; ChangeOilCB: TCheckBox;

ChangeFiltCB: TCheckBox; RotateCB: TCheckBox;

procedure ExitBtnClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure RefreshTimerTimer(Sender: TObject); procedure StatusTimerTimer(Sender: TObject); procedure SendBtnClick(Sender: TObject); procedure AllRBClick(Sender: TObject); procedure OneRBClick(Sender: TObject);

private

NumReceivers : Integer; procedure RefreshRecipientGroup;

procedure ShowStatus(MsgNum : Integer); public

{ Public declarations } end;

var

SenderMainForm: TSenderMainForm;

implementation

{$R *.DFM}

procedure TSenderMainForm.RefreshRecipientGroup; var

CurrReceivers : Integer; i : Integer;

begin

CurrReceivers := MsgSender1.NumReceivers; if NumReceivers <> CurrReceivers

then begin

NumReceivers := CurrReceivers; NumRcvrsLabel.Caption := IntToStr(NumReceivers); if NumReceivers > 0

then begin

OneRB.Enabled := True;

OneCombo.Items.Clear;

MsgSender1.UpdateReceiverList;

for i := 0 to MsgSender1.ReceiverList.Count - 1 do OneCombo.Items.Add(MsgSender1.ReceiverList[i]); OneCombo.ItemIndex := 0;

OneCombo.Enabled := OneRB.Checked; end

else begin

AllRB.Checked := True;

OneRB.Enabled := False; OneCombo.Text := ''; OneCombo.Enabled := False;

end;

ShowStatus(mdRcvChange);

end;

end;

procedure TSenderMainForm.ShowStatus(MsgNum : Integer); var

Msg : ShortString; begin

case MsgNum of

mdReady : Msg := 'Ready'; mdSuccess : Msg := 'Complete'; mdNoReply : Msg := 'No reply';

mdRcvChange : Msg := 'Number of receivers changed'; else

Msg := 'Unknown status response'; end; { case }

StatusLabel.Caption := Msg;

StatusTimer.Enabled := True; end;

procedure TSenderMainForm.ExitBtnClick(Sender: TObject); begin

Close;

end;

procedure TSenderMainForm.FormCreate(Sender: TObject); begin

NumRcvrsLabel.Caption := IntToStr(MsgSender1.NumReceivers); AllRB.Checked := True;

OneRB.Enabled := False; OneCombo.Enabled := False; ShowStatus(mdReady);

end;

procedure TSenderMainForm.RefreshTimerTimer(Sender: TObject); begin

RefreshRecipientGroup;

end;

procedure TSenderMainForm.StatusTimerTimer(Sender: TObject); begin

StatusTimer.Enabled := False; StatusLabel.Caption := ''; end;

procedure TSenderMainForm.SendBtnClick(Sender: TObject); var

Status : Integer;

RcvrNum : Integer;

begin

with MsgSender1 do if AllRB.Checked then begin

if ChangeOilCB.Checked

then AllBroadcast(mdSetChangeOil, 0) else AllBroadcast(mdResetChangeOil, 0);

if ChangeFiltCB.Checked

then AllBroadcast(mdSetChangeFilter, 0) else AllBroadcast(mdResetChangeFilter, 0);

if RotateCB.Checked

then Status := AllBroadcast(mdSetRotateTires, 0) else Status := AllBroadcast(mdResetRotateTires, 0);

ShowStatus(Status); end

else begin

RcvrNum := StrToInt(OneCombo.Items[OneCombo.ItemIndex]); if ChangeOilCB.Checked

then OneBroadcast(RcvrNum, mdSetChangeOil, 0) else OneBroadcast(RcvrNum, mdResetChangeOil, 0);

if ChangeFiltCB.Checked

then OneBroadcast(RcvrNum, mdSetChangeFilter, 0) else OneBroadcast(RcvrNum, mdResetChangeFilter, 0);

if RotateCB.Checked

then Status := OneBroadcast(RcvrNum, mdSetRotateTires, 0) else Status := OneBroadcast(RcvrNum, mdResetRotateTires, 0);

ShowStatus(Status);

end;

ChangeOilCB.Checked := False; ChangeFiltCB.Checked := False; RotateCB.Checked := False; end;

procedure TSenderMainForm.AllRBClick(Sender: TObject); begin

OneCombo.Enabled := False; end;

procedure TSenderMainForm.OneRBClick(Sender: TObject); begin

OneCombo.Enabled := 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.

To access the contents, click the chapter and section titles.

Kick Ass Delphi Programming

Go!

Keyword

(Publisher: The Coriolis Group)

Author(s): Don Taylor, Jim Mischel, John Penman, Terence Goggin

ISBN: 1576100448

Publication Date: 09/01/96

Search this book:

Go!

-----------

Each time RefreshTimer fires, it calls the RefreshRecipientGroup method.

RefreshRecipientGroup determines whether the number of registered receivers has changed since the last inquiry. If so, a status indicator is updated. If there is at least one receiver, the list of items in the combo box is updated with the indexes of the receivers. If there are no receivers registered, the combo box is disabled.

The Send button’s OnClick handler is the busiest routine on this form. If commands are to be sent to all registered receivers, SendBtnClick simply composes three messages—one for each check box—and uses the MsgSender’s AllBroadcast method to send the messages on their way. If the commands are to be sent to a single receiver, SendBtnClick composes the messages, but sends them via the OneBroadcast method, computing the receiver’s index number from the combo box’s item index.

A ShowStatus method is provided to display the results of some of the operations, including a change in the number of receivers, and the response to a transmitted command. StatusTimer automatically blanks the status display after three seconds.

I fired off the Sender app, then brought up the Receiver app. They worked famously, as shown in Figure 15.7. At the urging of the crowd, I brought up more instances. At one point, I had two Senders and four Receivers on the screen, all working perfectly. Using the “One receiver” radio button and combo box, I could send individual commands to any of the receivers.

FIGURE 15.7 Sender and Receiver at runtime.

A Rude Awakening

I had met the challenge of the day, and although it had been the longest afternoon of my life, I had performed well. I felt good.

“And in conclusion,” I said to the assembled masses, “there isn’t any problem that a combination of persistence and determination can’t overcome. Thank you, ladies and gentlemen, for being here. You’ve been a wonderful audience.”

I stood back from the microphone, ready to accept the inevitable applause. I had no idea what was about to happen.

“Sounds like ‘Spam’ to me,” shouted the greaseball with the chicken in his lap.

“Yea—let’s flame him!” yelled his toothless companion with the billiard ball head.

It was a matter of unfortunate timing that brought four staff members into the room at that moment, prepared to distribute the golden, finger-like sponge cakes bursting with creme filling intended for the residents’ mid-afternoon snack. An instant later those palatable pastries had turned into weapons of wrath, hundreds of them pelting my person.

Out of the corner of my eye, I saw the toothless old geezer heading in my direction, climbing up onto the stage, making his way right up to me, and finally, shoving his wrinkled face so close to mine that our noses touched. Whoever said that bad breath is better than no breath at all was overly optimistic. This guy was, for me, the ultimate argument against growing old.

“Whaddya want with me?” I asked him.

“I just want you to know what it’s gonna be like for you, if you don’t take better care of yourself,” he said, looking me straight in the eye. “Count on it.”

I stared back at his weak brown eyes through lenses as thick as soda bottles. There was something familiar about those eyes. Then it struck me.

“You’re…me!” I shouted.

“In yer dreams, Bud,” he replied. Then he began to laugh....

My eyes snapped open and I sat bolt upright. Beads of sweat poured down my face as I fought to regain my bearings. I had never left. I was sitting in the recliner in my office, the half-full pizza box still sitting on my lap. I got up, wiping the sweat from my forehead on my sleeve. I walked to the sink and doused my face with cold water.

I hate dream sequences, I thought. But it was no use. I was just a two-bit character in an expensive technical book, and I knew it. Perhaps tomorrow would be a better day.

I grabbed a bottle of Purely Poulsbo from the fridge and started to contemplate what had happened. Maybe Helen had been right after all. Perhaps I should take better care of myself. Balanced meals. Vitamin supplements. More

exercise.

I picked up the pizza box and tossed it in the trash bin. I could do better.

This time out, The Author had given me a glimpse at one possible scenario. If that scenario was intended to be someone’s future, I didn’t want it to be mine.

I guess time and cotton briefs are a lot alike—they can slowly creep up on you, and if you don’t do anything about it, you can eventually find yourself in a really tight situation.

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.

To access the contents, click the chapter and section titles.

Kick Ass Delphi Programming

Go!

Keyword

(Publisher: The Coriolis Group)

Author(s): Don Taylor, Jim Mischel, John Penman, Terence Goggin

ISBN: 1576100448

Publication Date: 09/01/96

Search this book:

Go!

-----------

Index

32-bit console applications API functions, 9 creating, 6

defined, 4

filter applications, 10 hello world example, 6 I/O functions, 8

in Delphi, 5 input, 8 output, 8

PeekConsoleInput, 9

PROJECT1.DPR, 6 text file I/O routines, 9 uses statement, 7 Windows vs. DOS, 4 WriteConsole, 9

3D fractal landscape

applying randomness, 170 bending, 155, 170 DATABASE.PAS, 163 display modes, 182 DISPLAY.PAS 171 displaying, 171

dividing, 156 Draw3Vertices(), 182 drawing, 171

drawing order and triangle orientation, 184 DrawPixels(), 183

DrawTriangle(), 184 envelope value, 170 filled mode, 184 fl3, 185

fractal defined, 155 FractureTriangle(), 158, 171 generating, 171

generating a landscape, 155 GLOBAL.PAS example, 160 landcolor(), 185

outline mode, 183 Plasma Routines, 185

plies vs. number of triangles, 163 Plys argument, 171

Project() Routine, 182 rendered mode, 184 shared edges, 156 square array, 162 triangular array, 159 triple data type, 159, 162 Tvertex, 159, 162

A

Active property, 384

Alignment property, 362

Applications

after.src, 200

and Win95 vs. Win 3.1, 388 before.src, 200

calendar example, 325

drag and drop operations. See Drag and Drop. exploring Win95 operations. See WalkStuf.

getting lists of modules and procedures from Win95, 390 making data global. See Data Modules.

messages, 359

playing a Wav file, 349 preventing program execution, 431 resizable windows, 358

resizing forms, 358 setting up themselves, 200 setup program, 200 setup.exe, 200

sharing memory through dlls, 93 single instance, 425

sizing windows, 359

taking advantage of windows API, 211 wm_getminmaxinfo, 359

B

BDE, 333

routines to pack paradox and dbase tables, 333 BeginDrag method, 324, 327

BevelOuter properties, 363

Borland Database Engine, 333. See BDE.

C

Calendar component, 325

relating a position to a date, 325 CD-ROM

badges.wav, 351 \chap1\orpheus, 325 memoedit.exe, 317 paktable.pas, 333 pictedit.exe, 318 starter.dpr, 263

Command line cmdline, 21

cmdline problems, 21 cmdline.pas, 15 optionrec, 20 options, 13 paramcount, 11 params program, 11 paramstr, 11

parsing, 14 processing, 11