📄 wizards_1.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 Wizards(1) <br>
发信站: BBS 水木清华站 (Thu Nov 5 21:59:25 1998) <b><font
color="#00ff00">WWW-POST</font></b> <br>
<br>
How To Write Delphi Wizards <br>
------------------------------------------------------------------------------ <br>
-- <br>
Delphi and C++Builder are truly open development environments, in that they <br>
have interfaces to enable us to integrate our own tools and experts within <br>
their IDE. This article will focus on writing and integrating Wizards <br>
(previously called Experts) with Delphi. The resulting (32-bits) Wizards will <br>
be compatible with Delphi 2.0x, Delphi 3 and C++Builder.
<br>
Delphi has four kinds of Wizards: Project Experts, Form Experts, Standard <br>
Experts and (32-bits only) AddIn Experts. The first two can be found in the <br>
Repository, Standard Experts can be found under the Help menu (like the <br>
Database Form Expert), while AddIn Experts have to provide their own <br>
menu-interface with the Delphi IDE (typicaly anywhere in the menu except for <br>
the Help Menu, which seems to be reserved for Standard Experts only).
<br>
<br>
<br>
<br>
Project and Form Experts can be activated whenever you create a new Project <br>
or Form (just like Project and Form Templates). Standard and AddIn Experts <br>
are the other kind of Wizards that generally do not create a new project or <br>
form, but provide some kind of information, or only create a new file or <br>
unit. <br>
If you've ever tried an Wizard, you know what power and ease they can bring <br>
to you. The Project Expert develops an entire project for you based on your <br>
specific preferences (like for example the Application Wizard). The Form <br>
Experts develop custom forms that are added to your current project. The <br>
Database Form Expert, for example, generates a form that displays data from <br>
an external database. These example Wizards are not just external tools that <br>
can be started from Delphi, they actually communicate with Delphi and are an <br>
integrated part of the development environment. While this is not so strange <br>
for the existing Delphi Experts (after all, they were developed and added by <br>
the same team that developed Delphi in the first place, and we all know <br>
Delphi's IDE is written in Delphi), it sounds intriguing at least to know <br>
that we, too, can write a Delphi Wizard that is able to communicate with <br>
Delphi in the same way. Could we actually write an Wizard that also opens <br>
files in the IDE, that can be used to start a new project from scratch? Yes, all this is possible, and more, as we will see <br>
shortly! <br>
<br>
1. TIExpert Interface <br>
The major reason why everybody thinks writing custom Wizards is difficult, is <br>
because they are not documented. Not in the manuals or on-line Help, that is <br>
(they are documented in my book The Revolutionary Guide to Delphi 2 and in my <br>
column in The Delphi Magazine). If you take a look at the documentation and <br>
source code on your harddisk, you'll find some important files and even two <br>
example Wizards that are installed automatically by Delphi itself. The <br>
important example files can be found in the DOC, SOURCE\VCL or <br>
SOURCE\TOOLSAPI subdirectories, and the main files are EXPTINTF.PAS, <br>
TOOLINTF.PAS, VIRTINTF.PAS and SHAREMEM.PAS. The first one shows how to <br>
derive and register our own Wizard, while the second one shows how to use the <br>
tool-services of Delphi to make the integration with the IDE complete.
<br>
<br>
In order to start working on a custom wizard, we have to take a look at the <br>
abstract base class definition TIExpert in EXPTINTF.PAS, which is as follows <br>
for the 32-bits versions of Delphi: <br>
<br>
<br>
Type <br>
TExpertStyle = (esStandard, esForm, esProject, esAddIn);
<br>
TExpertState = set of (esEnabled, esChecked); <br>
<br>
TIExpert = class(TInterface) <br>
public <br>
{ Expert UI strings } <br>
function GetIDString: string; virtual; stdcall; abstract;
<br>
function GetName: string; virtual; stdcall; abstract;
<br>
function GetAuthor: string; virtual; stdcall; abstract;
<br>
function GetStyle: TExpertStyle; virtual; stdcall; abstract;
<br>
function GetMenuText: string; virtual; stdcall; abstract;
<br>
function GetState: TExpertState; virtual; stdcall; abstract;
<br>
function GetGlyph: HICON; virtual; stdcall; abstract;
<br>
function GetComment: string; virtual; stdcall; abstract;
<br>
function GetPage: string; virtual; stdcall; abstract;
<br>
<br>
{ Launch the Expert } <br>
procedure Execute; virtual; stdcall; abstract;
<br>
end; <br>
<br>
2. TGenericExpert: Hello, World! <br>
If we want to derive our own Wizard, say TGenericExpert, we have to derive it <br>
from the abstract base class TIExpert, which has seven or nine abstract <br>
member functions (GetStyle, GetName, GetComment, GetGlyph, GetState, <br>
GetIDString and GetMenuText, and for the 32-bits versions of Delphi also <br>
GetAuthor and GetPage) and one member procedure Execute. Since TIExpert is an <br>
abstract base class, we need to override every function we need for any <br>
particular Wizard. <br>
<br>
<br>
unit Generic; <br>
interface <br>
uses <br>
Windows, ExptIntf; <br>
<br>
Type <br>
TGenericExpert = class(TIExpert) <br>
public <br>
{ Expert Style } <br>
function GetStyle: TExpertStyle; override; <br>
<br>
{ Expert Strings } <br>
function GetIDString: string; override; <br>
function GetName: string; override; <br>
function GetAuthor: string; override; <br>
function GetMenuText: string; override; <br>
function GetState: TExpertState; override; <br>
function GetGlyph: HICON; override; <br>
function GetComment: string; override; <br>
function GetPage: string; override; <br>
<br>
{ Expert Action } <br>
procedure Execute; override; <br>
end; <br>
<br>
procedure Register; <br>
<br>
implementation <br>
uses <br>
Dialogs; <br>
<br>
{ The implementation details of TGenericExpert will follow in the text }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -