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

(Ebook - Pdf) Kick Ass Delphi Programming

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

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!

-----------

Stepping Out

They say when the going gets tough, the tough make coffee. I was at that point, so I brewed a pot of Scandinavian blend and set to designing a demo application that would use several of the WalkStuf routines. A running version of what I came up with is shown in Figure 13.8. The code appears in Listing 13.8.

FIGURE 13.8 The Windows 95 Walking Demo taking a walk.

Listing 13.8 Code for the Walking Demo

{———————————————————————————————————————————————————}

{

The Walking Demo

}

{

WALKMAIN.PAS : Main Unit

}

{

By Ace Breakpoint, N.T.P.

}

{

Assisted by Don Taylor

}

{

 

}

{ This program demonstrates some techniques for

}

{ "walking" through the Win95 system fo get

}

{ specific system-wide information.

}

{

 

}

{ Written for *Kick-Ass Delphi Programming*

}

{ Copyright (c) 1996 The Coriolis Group, Inc.

}

{

Last Updated 3/28/96

}

{———————————————————————————————————————————————————} unit WalkMain;

interface

uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,

Dialogs, WalkStuf, Grids, StdCtrls, ExtCtrls;

type

TForm1 = class(TForm) ModuleGrid: TStringGrid; RefreshBtn: TButton; QuitBtn: TButton; ModuleRBGroup: TRadioGroup; ProcessesLabel: TLabel; ProcessListBox: TListBox; ModulesLabel: TLabel;

procedure QuitBtnClick(Sender: TObject); procedure RefreshBtnClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure ModuleRBGroupClick(Sender: TObject); procedure ProcessListBoxClick(Sender: TObject);

private

TheList : TStringList; procedure RefreshForm;

procedure DisplayProcessModules; procedure ClearModuleGrid; procedure FillProcessList; procedure FillModuleGrid;

public

{ Public declarations } end;

var

Form1: TForm1;

implementation

{$R *.DFM}

{

Return a string of spaces of the specified length.

}

function Spaces(Size : Integer) : String; begin

Result := '';

while Length(Result) < Size do Result := Result + ' '; end;

{

Clear the screen elements, retrieve data and update the screen.

}

procedure TForm1.RefreshForm; begin

ClearModuleGrid;

ProcessListBox.Clear;

TheList := GetSystemProcessList(ws_FullPath, ws_DupesOK); FillProcessList;

ProcessesLabel.Caption :=

'System processes: ' + IntToStr(TheList.Count);

TheList.Free;

case ModuleRBGroup.ItemIndex of 0 : begin

TheList := GetSystemModuleList

(ws_NoDirectory, ws_Unique, ws_InstanceCount); FillModuleGrid;

ModulesLabel.Caption :=

'System-wide modules: ' + IntToStr(TheList.Count); TheList.Free;

end;

1 : begin

TheList := GetSystemModuleList

(ws_NoDirectory, ws_Unique, ws_InstanceCount); if TheList.Count > 0

then begin

ProcessListBox.ItemIndex := 0; DisplayProcessModules;

end;

end; end; { case }

end;

{

Special screen update procedure that retrieves the module data for the currently selected process.

}

procedure TForm1.DisplayProcessModules; var

Idx : Integer; s : String;

p : Integer; begin

if ProcessListBox.Items.Count > 0 then begin

ClearModuleGrid;

Idx := ProcessListBox.ItemIndex;

TheList := GetProcessModules(ProcessListBox.Items[Idx], ws_NoDirectory, ws_InstanceCount);

if TheList.Count > 0

then for Idx := 1 to TheList.Count do begin

s := TheList.Strings[Idx - 1]; p := pos('<', s);

ModuleGrid.Cells[0, Idx] := copy(s, 1, p - 1); delete(s, 1, p);

s := Spaces(15) + s; ModuleGrid.Cells[1, Idx] := s;

ModuleGrid.RowCount := ModuleGrid.RowCount + 1; end;

ModulesLabel.Caption := 'Modules for this process: ' + IntToStr(TheList.Count);

TheList.Free;

end;

end;

{

Clear all rows in the Module String Grid, and reset the number of rows to one.

}

procedure TForm1.ClearModuleGrid; var

Idx : Integer; begin

for Idx := 1 to ModuleGrid.RowCount - 1 do begin

ModuleGrid.Cells[0, Idx] := '';

ModuleGrid.Cells[1, Idx] := ''; end;

ModuleGrid.RowCount := 2; end;

{

Fill in the Process listbox, line by line, from the global String List.

}

procedure TForm1.FillProcessList; var

Idx : Integer; begin

if TheList.Count > 0

then for Idx := 0 to TheList.Count - 1 do ProcessListBox.Items.Add(TheList.Strings[Idx]);

end;

{

Fill in the Module String Grid, line by line, from the global String List.

}

procedure TForm1.FillModuleGrid; var

s : String;

p : Integer;

Idx : Integer; begin

if TheList.Count > 0 then begin

for Idx := 1 to TheList.Count do begin

s := TheList.Strings[Idx - 1]; p := pos('<', s);

ModuleGrid.Cells[0, Idx] := copy(s, 1, p - 1); delete(s, 1, p);

s := Spaces(15) + s;

ModuleGrid.Cells[1, Idx] := s; ModuleGrid.RowCount := ModuleGrid.RowCount + 1; end; { for }

end;

end;

procedure TForm1.QuitBtnClick(Sender: TObject); begin

Close;

end;

procedure TForm1.RefreshBtnClick(Sender: TObject); begin

RefreshForm;

end;

procedure TForm1.FormCreate(Sender: TObject); begin

ModuleGrid.Colwidths[1] :=

ModuleGrid.Width - ModuleGrid.ColWidths[0] - 22; ModuleGrid.Cells[0, 0] := 'Name'; ModuleGrid.Cells[1, 0] := 'System instances'; ModuleRBGroup.ItemIndex := 0;

end;

procedure TForm1.ModuleRBGroupClick(Sender: TObject); begin

RefreshForm;

end;

procedure TForm1.ProcessListBoxClick(Sender: TObject); begin

if ModuleRBGroup.ItemIndex > 0 then DisplayProcessModules; 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!

-----------

There’s nothing really special about the code in the demo. The upper window always shows all active processes in the system snapshot. If the radio button marked “System wide” is selected, the lower window lists all modules in the system, including the number of instances of each. If the “Selected process only” button is selected, the lower window lists only the modules for the process highlighted in the upper window. And of course, the Refresh button takes a new snapshot and updates the screen. The main thing to remember is that every call to a WalkDemo routine that returns a string list does so by creating a new object; that object must later be disposed exactly once.

This was all quite instructional, and a lot of fun as well. But my investigations only scratched the surface, and there are many more things to learn. One of the things I discovered is that the ToolHelp routines are compatible only with Win95 and not NT, at least for now.

I get the distinct impression that I’ll be able to use some of this stuff in my applications. And I’ll certainly have to come back and investigate more thoroughly when I have more time.

End of entry, March 28.

When Ace and Helen arrived at the office, there was still no word on the DNA test. Ace took out a bottle of Purely Poulsbo from the refrigerator, and found a couple of clean glasses in the cupboard. He poured two fingers’ worth into each glass, then handed one to Helen. He had no more than touched the glass to his lips when there came a sharp rap at the door.

It was Marge Reynolds. Ace could hear excitement in her voice as she exchanged pleasantries with Helen. Marge quickly came to the point.

“I know you’ve been looking for clues to last night’s robbery,” she began. “I saw you out there digging through the mud in the parking lot this afternoon. But I’ve been keeping my eyes open, too—looking for anything suspicious.”

She paused for an acknowledgment of interest.

“Go on,” he urged.

“This evening, as I was walking past the public phone booth on the other side of the courtyard you know, the one that faces your kitchen window—I found a piece of paper stuck in a bush, about a foot above the ground.”

Marge fumbled around in the pocket of her bulky knit sweater. “I’m sure it’s here somewhere. I put it—oh, here it is,” she said, pulling out a lavender-colored scrap of paper and examining it one more time. “It looks like it was written by a woman. It’s got your name and phone number on it, and two other words: ‘kidnapped heiress.’ Do you think it means anything?”

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!

-----------

CHAPTER 14

The Oracle Returns

DON TAYLOR

Sharing Event Handlers

Windows 95 Memory Files

Detecting Multiple Instances Of An Application

Preventing Application Execution

Floating Toolbars

While the Delphi Avenger discovers how to make Delphi apps detect both themselves and Delphi, (floating a toolbar as a bonus) Ace detects one too many X’s in a very strange equation—but ultimately drags the case to a jaw-dropping conclusion.

Ace switched on the Halogen lamp on his desk and held the lavender piece of

paper up to the light.

“Pretty expensive stuff,” he said. “It’s fine linen. I can just make out what appears to be the edge of a watermark.” He turned the scrap so the light coming from the lamp reflected off the paper. “The writing’s in a feminine hand, all right,” he said. “By the size of the loops, I’d say the woman who wrote this has a strong personality, consistent with the woman who had the bravado to call me last night. And this was definitely written with a very expressive pen, probably a Habasher No. 4374 tip, using what appears to be Mandolay’s ‘Nightshade’ ink. Other than that, there’s not much I can deduce.”

“May I see it?” asked Helen.

“Sure,” Ace replied. Handing over the note, he added, “One more thing. You’ll notice the paper has been scented with some kind of perfume.”

Helen’s eyes widened as she passed the paper scrap under her nose. “This is not just any ordinary perfume,” she said. “It’s a very expensive fragrance.

Chez Monieux.”

“Okay, so it’s expensive perfume,” he said, a bit testily.

“I didn’t mean to belittle you in any way, Sweetheart. It’s just that women notice little things that men often don’t. In this case, it’s that only a sophisticated, well-to-do woman would wear this perfume—Chez Monieux.”

“Hey, lighten up. I already said she used expensive paper, and a very nice pen and ink, didn’t I? Just because I’m not a perfume expert—”

“I think what Helen is trying to say,” Marge interjected, “is the name of the perfume is Chez Monieux.”

Ace froze for a moment, as if wondering what to say. His eyes darted quickly between those of Marge and Helen. “I knew that,” he replied guardedly.

“Remember?” Helen said. “It’s part of that new exclusive line of fashion accessories produced for Muffy. You know, the Pure Prophet collection?”

“I knew that, too,” Ace said. “But where does all this get us?”

“Well, I have a theory,” Helen began. “I think Melvin Bohacker has for some time been looking to get even with you. He has probably recently gotten involved with a woman of means; a woman used to having her own way about things, and someone to whom pride is a precious commodity.”

She looked to her companions for a confirmation to continue. Ace rolled his eyes, but Marge was obviously hanging on Helen’s every word.

“When this woman—let’s call her ‘Madame X’—found out about how Melvin had lost face because of you, she coaxed him to get even. Together, they concocted the plan they executed last night: Driving her car, they pulled in here and parked in the space next to yours. He got out and hid in the shadows somewhere while she walked to the pay phone on the other side of the courtyard. From there, she was able to watch you through your kitchen window as she dialed the number she had earlier scrawled on a corner of her personal note paper.”

“So how did the note get where it was found?” Ace asked.

“I have a theory about that, too. The pay phone is one of those open types, mounted on a pole. Madame X probably laid the note down and it was blown away by a puff of wind. There’s a light by the pole. But if the note was blown even a few feet away, it would have been in relative darkness. She was probably in a hurry, and may not even have missed the note.”

“And the glove?”

“Bohacker undoubtedly wore gloves to break into your apartment, so he wouldn’t leave any fingerprints. He probably took them off as he was getting

back into the car, and dropped one on the ground. He may have run over it with the car, partially burying it in the mud.”

“I’m sorry,” Ace said, waving his hand in front of his face. “It all sounds plausible enough, except for one thing: Bohacker isn’t capable of doing it, even with the goading of some rich babe—heiress or not.”

Helen sighed. “I guess we’ll just have to wait for the results from the DNA testing. That should prove who is right, once and for all.”

“DNA testing?” Marge asked. “What about DNA testing? And what is this business with a glove?”

Ace recounted the story of the glove to Marge. It took nearly half an hour to describe all the details to her satisfaction.

“It’s sure been an exciting day,” she said. “I wish I could sit around here with you kids and wait for the test results. But there’s a new tenant moving into #193 tonight—a bachelor—and I want to see what kind of appliances he owns.”

Marge Reynolds walked to the front door, her polyester knit pants hugging every bulge, looking like a sack full of cats on their way to the Pound. She squeezed through the door and quietly closed it behind her.

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.