



免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
怎样编写DELPHI向导(二)After we c1ick onthe OK-button to add the generic unit with our GenericExpert to the DCLUSR30 package, we need to confirm that De1phi needs to rebui1d the package:After the package is rebui1t and insta11ed into the De1phi 3 IDE again, we can inspect the Package Editor and see that the generic unit is now part ofit. This simp1e examp1e a1ready i11ustrates that packages are not 1imited to components, but can contain Wizards as we11.When De1phi is done with compi1ing and 1inking COMPLIB.DCL or DCLUSR30.DPL,you can find our first new Wizard in the He1p menu:Just se1ect the Generic Wizard and it wi11 show the wor1d that it s a1ive: As we can see, on1y the Execute method contains any significant code, andthi s wi11 rerr阻in so for a11 Wizards to come. In order to avoid that we have to print a 10ng 1isting in this paper for an Wizard where on1y one method isre1evant, l 11 propose the fo11owing technique: 1et s use a tab1e to definethe nine methods, and on1y specify the Execute method in detai1. OurTGenericExpert wou1d then become the fo11owing: TGenericExpertGetSty1e: esStandardGetIDString: DrBob. TGenericExpertGetName: Generic WizardGetAuthor (win32): Bob Swart (aka Dr.Bob) GetMenuText: &Generic Wizard.GetState: esEnab1edlGetG1yph: 0GetPage (win32): GetComment:With on1y the Execute method out1ined in detai1 (see previous 1isting). Wewi11 use this notation in the rest of this session.3. TSyslnfoExpertInstead of just popping up a MessageD1g, we can show any form wed 1ike. In fact, this is just were the fun starts. Genera11y,we can consider our Wizardto consist of two parts: the Wizard engine and the form interface. Weve just seen how to 盯ite the Wizard engi时,and we a11 know how to write forminterfaces, so 1et s put these two together and write our firstsomething-more-than-trivia1 information Wizard. The information that 1 want the Wizard to present can be found in the SysUti1s unit, and consists of the country specific informatin regarding currency and date/time formattingconstants. In the on-1ine he1p we can find which constants are defined in SysUti1s, but we can t see their va1ue. This is unfortunate, since most of the time De1phi is of course up-and-running whi1e were deve1oping, soSysUti1s is active as we11 (remember: De1phi is written in De1phi!) andshould know about these values.So, using the Dialog Expert, we can create a Multipage dialog, using a TabbedNotebook, and give the three pages the names Currency, Date and Time. Next, we must drop a label on each of the pages, set autosize for each label to false, and make them about as big as the entire notebook (somultiple lines can be viewed). The source code for the form merely consists of putting the right values on the right places when the form is created (inthe OnCreate handler) , so nothing complex at all for the interface side of the Syslnfo Wizard. The engine of TSyslnfoExpert is as follows:TSyslnfoExpertGetStyle: esStandardGetIDString: DrBob. TSyslnfoExpertGetName: Syslnfo WizardGetAuthor (win32): Bob Swart (aka Dr.Bob) GetMenuText: &Syslnfo Wizard.GetState: esEnabledlGetGlyph: 0GetPage (win32): GetComment:The Execute method of the Syslnfo Wizard is almost as easy, since all we need to do is to create, show and free the form with the desired information.That s it. The source code for the Execute procedure is as follows:procedure TSyslnfoExpert.Execute;beginwith TSyslnfoForm.Create(nil) do beginShowModal; Freeendend Execute;And presto! Our first useful Wizard, showing information at design time that isn t available any other way:This is only the first of many examples where we will see an Wizard engine that will show an interface form to show (or get) information to the user. One source of information to provide (or actions to apply) can be obtained from the so-called toolservices interface Delphi offers us in the TIToolServices class.4. ToolServicesWeve seen some generic but in fact pretty much useless Wizard so far. In order to 盯ite truly more useful Wizards, we need to do something special inside the Execute method, like show a (more) interesting form in which a lot of things can happen, a bit like we introduced with the TSyslnfoExpert.Did you ever feel the need to load some project other than a .DPR file in theu1uIDnns E1tew? No? Never 盯itten any DLLs in De1phi? We11, 1 often have the need to open+Lunb1i rna .PAS or any fi1e with an extension other than .DPR inside the 1DE asoayTIfiTImy projeocpct.1n fact,my need is so big, 1 want to write an Wizard to he1p me in brows-ieeng over my disk and directories in search for a certain fi1e to openTinbnas a new pr+oL Ject.But is thisfpiv ossib1e? To answer this question, we need to take a 100k at!1irTOOL1NTF.PAS fro+mLTiDe1phi 1.0,the fi1e that contains the definition of+LTIToo1Services (thne 1 stands for 1nterface again) ,which is as follows:+iTypeTIToo1Services 二 c1ass(T1nterface)pub1ic Action interfaces function C1oseProject: Boo1ean; virtua1; export; abstract;function OpenProject(const ProjName: string): Boo1ean; virtua1; export;abstract;function OpenProject1nfo(const ProjName: string): Boo1ean; virtua1;export; abstract;function SaveProject: Boo1ean; virtua1; export; abstract;function C1oseFi1e(const Fi1eName: string): Boo1ean; virtua1; export;abstract;function SaveFi1e(const Fi1eName: string): Boo1ean; virtua1; export;abstract;function OpenFi1e(const Fi1eName: string): Boo1ean; virtua1; export;abstract;function Re1oadFi1e(const Fi1eName: string): Boo1ean; virtua1; export;abstract;function Moda1Dia1ogBox(1nstance: THand1e; Temp1ateName: PChar; WndParent: HWnd;Dia1ogFunc: TFarProc; 1nitParam: Long1nt): 1nteger; virtua1; export;abstract;function CreateModu1e(const Modu1eName: string; Source, Form: T1Stream; CreateF1ags: TCreateModu1eF1ags): Boo1ean; virtua1; export; abstract;Project/U1 information function GetParentHand1e: 因NND; virtua1; export; abstract; function GetProjectName: string; virtua1; export; abstract; function GetUnitCount: 1nteger; virtua1; export; abstract;function GetUnitName(1ndex: 1nteger): string; virtua1; export; abstract;function GetFormCount: 1nteger; virtua1; export; abstract;function GetFormName(1ndex: 1nteger): string; virtua1; export; abstract;function GetCurrentFi1e: string; virtua1; export; abstract;function 1sFi1eOpen(const Fi1eName: string): Boo1ean; virtua1; export;abstract;function GetNewModu1eName(var Unit1dent, Fi1eName: string): Boo1ean;virtua1; export; abstract; Component Library interface function GetModu1eCount: Integer; virtua1; export; abstract;function GetModu1eName(Index: Integer): string; virtua1; export;abstract;function GetComponentCount(Modlndex: Integer): Integer; virtua1; export;abstract;function GetComponentName(Modlndex,Complndex: Integer): string; virtua1;export; abstract;function Insta11Modu1e(const Modu1eName: string): Boo1ean; virtua1;export; abstract;function Compi1eLibrary: Boo1ean; virtua1; export; abstract;Error hand1ing procedure RaiseException(const Message: string); virtua1; export;abstract;end;imp1ementationThe Too1 services object is created on the app1ication (De1phi/C+Bui1der) side, and is passed to the VCS/Expert Manager DLL during initia1ization. Note that the app1ication (De1phi/C+Bui1der) is responsib1e for creating andfreeing the interface object, and the c1ient shou1d never free the interface.The fo11owing Too1Services functions are avai1ab1e to the c1ient (for De1phi1. 0 as we11 as 2. Ox and 3) :ActionsC1oseProjectreturns True if no project open, or if the current1y open project can be closed.OpenProjectreturns True if the named project can be opened. You have to pass an empty string to create a new project and main form.OpenProjectlnforeturns True if the named project fi1e can be opened. This routine bypasses a11 the norma1 project 10ad features (such as 10ading a desktop fi1e,showing the source code, etc) , and simp1y opens the .DPR and .OPT fi1es.SaveProjectreturns True if the project is unmodified, if there is no project open, or if the open project can be saved.C1oseFi1ereturns True if the specified fi1e is not current1y open, or if it can be closed.OpenFi1ereturns True if the specified fi1e is a1ready open or can be opened. Re1oadFi1ereturns True if the fi1e is a1ready open and was re10aded from disk.(NOTE:This wi11 not perform any checking of the current editor state). RefreshBufferscauses the IDE to check the time/date stamp of each open file to determine if the file has changed on disk. If so, the file is re-read.ModalDialogBoxused by non-VCL DLL s to present a dialog box which is modal. Note that DLLs盯itten using VCL can simply call a form s ShowModal function. CreateModuleWill create new module from memory irr阻ges of the source and, optionally, theform file.The TCreateModuleFlags are:cmAddToProject: Add the new module to the currently open project. cmShowSource: Show the source file in the top-most editor window.cmShowForm: If a form is created, show it above the source.cmUnNamed: Will mark the module as unnamed which will cause the SaveAs dialog to show the first time the user attempts to save the file.cmNewUnit: Creates a new unit and adds it to the current project. NOTE: all other parameters are
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2023年安徽省合肥市笔试辅警协警真题(含答案)
- 海南省东方市东方中学2024-2025学年高二下学期期中考试英语试题
- 03-01中值定理章节课件
- 幼儿园小班体育教案《碰碰车》
- 2025年高等数学应用能力考试试卷及答案
- 08-05二重积分章节课件
- 陶笛特色课培训
- 部编版语文三年级语文下册《燕子》课件
- 2025年心理测试师职业资格考试试题及答案
- 早产护理常规实施要点
- 老人集中供养管理制度
- 音标考试卷及答案二年级
- 四川省成都市武侯区2023-2024学年八年级下学期语文期末试卷(含答案)
- 幼小衔接合同协议书
- 2025年福建省粮食行业职业技能竞赛(粮油质量检验员)备赛试题库(含答案)
- 2025上半年水发集团社会招聘(391人)笔试参考题库附带答案详解
- 2025芜湖市鸠江区裕溪口街道社区工作者考试真题
- 2025年广东省深圳市龙华区中考数学二模试卷
- 熊胆粉初稿完整版本
- 坚守廉洁底线弘扬清风正气
- 小区物业管理计划书:范文
评论
0/150
提交评论