📄 wizards_1.htm
字号:
<br>
<br>
procedure Register; <br>
begin <br>
RegisterLibraryExpert(TGenericExpert.Create) <br>
end {Register}; <br>
end. <br>
<br>
Let's have a closer look at our generic Wizard from this listing. Since <br>
TIExpert is an abstract base class, we need to override every function we <br>
need for our TGenericExpert. First of all, we need to specify the style of <br>
the Wizard with the GetStyle method that can return one of three (or four) <br>
possible values: esStandard to tell the IDE to treat the interface to this <br>
Wizard as a menu item on the Help menu, esForm to tell the IDE to treat this <br>
Wizard interface in a fashion similar to form templates, or esProject to tell <br>
the IDE to treat this interface in a fashion similar to project templates. <br>
For 32-bits Delphi Wizards only, we can also return esAddIn here, to indicate <br>
that this is a special klind of Wizard that handles all its own interfaceing <br>
to the IDE through the TIToolServices interface. For our TGenericExpert, a <br>
Standard type Wizard that only shows a MessageDlg to say hello to the world, <br>
we can use the esStandard style. <br>
<br>
function TGenericExpert.GetStyle: TExpertStyle; <br>
begin <br>
Result := esStandard <br>
end {GetStyle}; <br>
<br>
The GetIDString should be unique to all Wizards that could be installed. By <br>
convention, the format of the string is: CompanyName.ExpertFunction, like <br>
Borland.Expert or DrBob.GenericExpert. <br>
<br>
function TGenericExpert.GetIDString: String; <br>
begin <br>
Result := 'DrBob.TGenericExpert' <br>
end {GetIDString}; <br>
<br>
After we've set the style of the Wizard, all we need to do is fill the other <br>
options accordingly. The GetName must return a unique descriptive name <br>
identifying this Wizard, like 'Generic Wizard'. <br>
<br>
function TGenericExpert.GetName: String; <br>
begin <br>
Result := 'Generic Wizard' <br>
end {GetName}; <br>
<br>
If the style is esForm or esProject, then - for 32-bits versions of Delphi <br>
only - we need to return a valid name for the Author. In this case, the style <br>
is esStandard, so we can return an empty string instead. For an esForm or <br>
esProject style Wizard the name would be displayed in the Object Repository <br>
of the 32-bits versions of Delphi. <br>
<br>
{$IFDEF WIN32} <br>
function TGenericExpert.GetAuthor: String; <br>
begin <br>
Result := 'Bob Swart (aka Dr.Bob)' { although not needed for esStandard <br>
} <br>
end {GetAuthor}; <br>
{$ENDIF} <br>
<br>
If style is esForm or esProject then GetGlyph should return a handle to a <br>
bitmap (for Delphi 1) or icon (for Delphi 2.0x and 3) to be displayed in the <br>
form or project list boxes or dialogs. This bitmap should have a size of <br>
60x40 pixels in 16 colours. The icon should be 32x32 in 16 colours. Again, <br>
since the style is just esStandard for our TGenericExpert, we can return 0 <br>
here. We can even combine the 16- and 32-bit version of GetGlyph here (0 is a <br>
valid value to indicate that an icon or bitmap is empty). Note that if we <br>
return a 0 when a bitmap or icon is needed, Delphi will use the default <br>
image. <br>
<br>
{$IFDEF WIN32} <br>
function TGenericExpert.GetGlyph: HICON; <br>
{$ELSE} <br>
function TGenericExpert.GetGlyph: HBITMAP; <br>
{$ENDIF} <br>
begin <br>
Result := 0 { not needed for esStandard }
<br>
end {GetGlyph}; <br>
<br>
If style is esForm or esProject then GetComment should return a 1 or 2 line <br>
sentence describing the function of this Wizard. Since the style is <br>
esStandard, we can return an empty string. <br>
<br>
function TGenericExpert.GetComment: String; <br>
begin <br>
Result := '' { not needed for esStandard }
<br>
end {GetComment}; <br>
<br>
If style is esForm or esProject then - only for 32-bits versions of Delphi - <br>
using GetPage we can specify the name of the page in the Object Repository <br>
where to place our Wizard. If we don't specify a name here, then the Wizard <br>
just gets added to the Default Form or Project page. Since we're writing an <br>
esStandard Expert, we don't need to supply a page name, so we can return an <br>
empty string again. <br>
<br>
{$IFDEF WIN32} <br>
function TGenericExpert.GetPage: String; <br>
begin <br>
Result := '' { not needed for esStandard }
<br>
end {GetPage}; <br>
{$ENDIF} <br>
<br>
If style is esStandard then GetMenuText should return the actual text to <br>
display for the menu item, like 'Generic Wizard'. Since this function is <br>
called each time the parent menu is pulled-down, it is even possible to <br>
provide context sensitive text. <br>
<br>
function TGenericExpert.GetMenuText: String; <br>
begin <br>
Result := '&Generic Wizard...' <br>
end {GetMenuText}; <br>
<br>
If the style is esStandard then GetState returning esChecked will cause the <br>
menu to display a checkmark. This function is called each time the Wizard is <br>
shown in a menu or listbox in order to determine how it should be displayed. <br>
We just leave it esEnabled for now. <br>
<br>
function TGenericExpert.GetState: TExpertState; <br>
begin <br>
Result := [esEnabled] <br>
end {GetState}; <br>
<br>
Finally, the Execute method is called whenever this Wizard is invoked via the <br>
menu, form gallery dialog, or project gallery dialog. Note that Execute is <br>
never called for an esAddIn style Wizard (this kind of Wizard will handle all <br>
its own interfacing to the IDE through the upcoming TIToolServices <br>
interface). The style will determine how the Wizard was invoked. In this <br>
case, we just call a MessageDlg in the Execute method to indicate that the <br>
Wizard is actually alive. <br>
<br>
procedure TGenericExpert.Execute; <br>
begin <br>
MessageDlg('Hello Nashville!', mtInformation, [mbOk], 0)
<br>
end {Execute}; <br>
<br>
To install our first Wizard, all we need to do is act like it's a new <br>
component: For Delphi 1.0, pick Options | Install, for Delphi 2.0x and 3 <br>
select Component | Install, and add it to the list of installed components.
<br>
Delphi 1 and 2 simply add the Wizard the the Component Library, but Delphi 3 <br>
needs to add it to a package - the DCLUSR30 package by default:
</p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -