⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wizards_1.htm

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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -