📄 wizards_2.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>怎样编写DELPHI向导(二)</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p align="center"><big><big><big>怎样编写DELPHI向导(二)</big></big></big></p>
<p>发信人: strayli (stray), 信区: Delphi <br>
标 题: How to write Delphi wizard(2) <br>
发信站: BBS 水木清华站 (Thu Nov 5 22:01:06 1998) <b><font
color="#00FF00">WWW-POST</font></b> <br>
<br>
After we click onthe OK-button to add the generic unit with our GenericExpert <br>
to the DCLUSR30 package, we need to confirm that Delphi needs to rebuild the <br>
package: <br>
After the package is rebuilt and installed into the Delphi 3 IDE again, we <br>
can inspect the Package Editor and see that the generic unit is now part of <br>
it. This simple example already illustrates that packages are not limited to <br>
components, but can contain Wizards as well.
<br>
When Delphi is done with compiling and linking COMPLIB.DCL or DCLUSR30.DPL, <br>
you can find our first new Wizard in the Help menu:
<br>
Just select the "Generic Wizard" and it will show the world that it's alive: <br>
As we can see, only the Execute method contains any significant code, and <br>
this will remain so for all Wizards to come. In order to avoid that we have <br>
to print a long listing in this paper for an Wizard where only one method is <br>
relevant, I'll propose the following technique: let's use a table to define <br>
the nine methods, and only specify the Execute method in detail. Our <br>
TGenericExpert would then become the following:
<br>
TGenericExpert <br>
GetStyle: esStandard <br>
GetIDString: DrBob.TGenericExpert <br>
GetName: Generic Wizard <br>
GetAuthor (win32): Bob Swart (aka Dr.Bob) <br>
GetMenuText: &Generic Wizard... <br>
GetState: [esEnabled] <br>
GetGlyph: 0 <br>
GetPage (win32): <br>
GetComment: <br>
With only the Execute method outlined in detail (see previous listing). We <br>
will use this notation in the rest of this session.
</p>
<p> <br>
3. TSysInfoExpert <br>
Instead of just popping up a MessageDlg, we can show any form we'd like. In <br>
fact, this is just were the fun starts. Generally, we can consider our Wizard <br>
to consist of two parts: the Wizard engine and the form interface. We've just <br>
seen how to write the Wizard engine, and we all know how to write form <br>
interfaces, so let's put these two together and write our first <br>
something-more-than-trivial information Wizard. The information that I want <br>
the Wizard to present can be found in the SysUtils unit, and consists of the <br>
country specific informatin regarding currency and date/time formatting <br>
constants. In the on-line help we can find which constants are defined in <br>
SysUtils, but we can't see their value. This is unfortunate, since most of <br>
the time Delphi is of course up-and-running while we're developing, so <br>
SysUtils is active as well (remember: Delphi is written in Delphi!) and <br>
should know about these values. <br>
<br>
So, using the Dialog Expert, we can create a Multipage dialog, using a <br>
TabbedNotebook, and give the three pages the names "Currency", "Date" and <br>
"Time". Next, we must drop a label on each of the pages, set autosize for <br>
each label to false, and make them about as big as the entire notebook (so <br>
multiple lines can be viewed). The source code for the form merely consists <br>
of putting the right values on the right places when the form is created (in <br>
the OnCreate handler), so nothing complex at all for the interface side of <br>
the SysInfo Wizard. The engine of TSysInfoExpert is as follows:
<br>
<br>
<br>
TSysInfoExpert <br>
GetStyle: esStandard <br>
GetIDString: DrBob.TSysInfoExpert <br>
GetName: SysInfo Wizard <br>
GetAuthor (win32): Bob Swart (aka Dr.Bob) <br>
GetMenuText: &SysInfo Wizard... <br>
GetState: [esEnabled] <br>
GetGlyph: 0 <br>
GetPage (win32): <br>
GetComment: <br>
<br>
The Execute method of the SysInfo Wizard is almost as easy, since all we need <br>
to do is to create, show and free the form with the desired information. <br>
That's it. The source code for the Execute procedure is as follows:
<br>
<br>
<br>
procedure TSysInfoExpert.Execute; <br>
begin <br>
with TSysInfoForm.Create(nil) do <br>
begin <br>
ShowModal; <br>
Free <br>
end <br>
end {Execute}; <br>
<br>
And presto! Our first "useful" Wizard, showing information at design time <br>
that isn't available any other way: <br>
<br>
<br>
This is only the first of many examples where we will see an Wizard engine <br>
that will show an interface form to show (or get) information to the user. <br>
One source of information to provide (or actions to apply) can be obtained <br>
from the so-called toolservices interface Delphi offers us in the <br>
TIToolServices class. <br>
<br>
4. ToolServices <br>
We've seen some generic but in fact pretty much useless Wizard so far. In <br>
order to write truly more useful Wizards, we need to do something special <br>
inside the Execute method, like show a (more) interesting form in which a lot <br>
of things can happen, a bit like we introduced with the TSysInfoExpert.
<br>
Did you ever feel the need to load some project other than a .DPR file in the <br>
IDE? No? Never written any DLLs in Delphi? Well, I often have the need to <br>
open a .PAS or any file with an extension other than .DPR inside the IDE as <br>
my project. In fact, my need is so big, I want to write an Wizard to help me <br>
in browsing over my disk and directories in search for a certain file to open <br>
as a new project. <br>
But is this possible? To answer this question, we need to take a look at <br>
TOOLINTF.PAS from Delphi 1.0, the file that contains the definition of <br>
TIToolServices (the "I" stands for Interface again), which is as follows:
<br>
<br>
<br>
unit ToolIntf; <br>
interface <br>
uses <br>
WinTypes, VirtIntf; <br>
<br>
Type <br>
TIToolServices = class(TInterface) <br>
public <br>
{ Action interfaces } <br>
function CloseProject: Boolean; virtual; export; abstract;
<br>
function OpenProject(const ProjName: string): Boolean; virtual; export; <br>
abstract; <br>
function OpenProjectInfo(const ProjName: string): Boolean; virtual; <br>
export; abstract; <br>
function SaveProject: Boolean; virtual; export; abstract;
<br>
function CloseFile(const FileName: string): Boolean; virtual; export; <br>
abstract; <br>
function SaveFile(const FileName: string): Boolean; virtual; export; <br>
abstract; <br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -