在刚刚开始编程阶段,自己一步步编写出一个登录窗体,或是一个能够对数据表记录进行增、删、改的窗体时,会感到非常的兴奋。但随着编程时间和编写项目的增加,会发现这种没有什么技术含量的窗体被不断的重复编写,于是乎开始思考有没有一种一劳永逸的办法可以帮助我们摆脱这种窘境呢?有的朋友或者会说,将这些做成一个标准的窗体存放在某个地主,在需要的时候将其Copy过来,然后略为修改。不可否认,这也是一种方法,但对于一个编程人员来说,这种方法很不专业。另一方法则相对更为专业,就是自已动手编写一个Expert。
Delphi是一个完全开放的开发集成环境,提供了一组ToolsAPI供开发者对其进行扩展(相关单元在Delphi的安装目录下的Source/ToolsAPI/中)。要编写自己的Expert需要引用其中的ExptIntf.pas文件,它定义了一个抽象基类TIExpert,任何自定义的Expert均要继承于他。
TIExpert=class(TInterface)
public
{ExpertUIstrings}
functionGetName:string;virtual;stdcall;abstract;
functionGetAuthor:string;virtual;stdcall;abstract;
functionGetComment:string;virtual;stdcall;abstract;
functionGetPage:string;virtual;stdcall;abstract;
{$IFDEFMSWINDOWS}
functionGetGlyph:HICON;virtual;stdcall;abstract;
{$ENDIF}
{$IFDEFLINUX}
functionGetGlyph:Cardinal;virtual;stdcall;abstract;
{$ENDIF}
functionGetStyle:TExpertStyle;virtual;stdcall;abstract;
functionGetState:TExpertState;virtual;stdcall;abstract;
functionGetIDString:string;virtual;stdcall;abstract;
functionGetMenuText:string;virtual;stdcall;abstract;
{LaunchtheExpert}
procedureExecute;virtual;stdcall;abstract;
end;
public
{ExpertUIstrings}
functionGetName:string;virtual;stdcall;abstract;
functionGetAuthor:string;virtual;stdcall;abstract;
functionGetComment:string;virtual;stdcall;abstract;
functionGetPage:string;virtual;stdcall;abstract;
{$IFDEFMSWINDOWS}
functionGetGlyph:HICON;virtual;stdcall;abstract;
{$ENDIF}
{$IFDEFLINUX}
functionGetGlyph:Cardinal;virtual;stdcall;abstract;
{$ENDIF}
functionGetStyle:TExpertStyle;virtual;stdcall;abstract;
functionGetState:TExpertState;virtual;stdcall;abstract;
functionGetIDString:string;virtual;stdcall;abstract;
functionGetMenuText:string;virtual;stdcall;abstract;
{LaunchtheExpert}
procedureExecute;virtual;stdcall;abstract;
end;
下面对这个类中的方法进行简要的说明
方法名称 | 描述 |
GetName | 子类必须改写此方法,给Expert指定一个唯一的名字 |
GetAuthor | 如果编写的是Form Export或Project Expert则子类必须改写此方法,给Expert指定作者,这个字串将出现在Object Repository中 |
GetComment | 如果编写的是Form Export或Project Expert则子类必须改写此方法,简单描述Expert的用途 |
GetPage | 如果编写的是Form Export或Project Expert则子类必须改写此方法,指定Expert出现在New Item窗体的哪个页面中 |
GetGlyph | 如果编写的是Form Export或Project Expert则子类必须改写此方法,指定Expert在New Item窗体中显示的图标,返回0值表示使用默认图标 |
GetStyle | 子类必须改写此方法,指定Expert类型,只能取以下四个值之一:esStandard, esForm, esProject, esAddIn |
GetState | 如果编写的是StandardExport则子类必须改写此方法,指定显示在Help中的Expert菜单状态 |
GetIDString | 子类必须改写此方法,提供一个不与其他任何Expert冲突的字符串,按照惯例,该字符串格式为CompanyName.ExpertFunction |
GetMenuText | 如果编写的是Standard Export则子类必须改写此方法,指定显示在Help中的Expert菜单标题 |
Execute | 如果编写的是Standard Export、Form Export或Project Expert则子类必须改写此方法,当点击菜单或是New Item中的Expert图标时会执行此方法。 |
下面这个Demo会在Delphi IDE的Help菜单中添加一个菜单项,点击之后会弹出一个对话框显示“This is Expert Demo.”。
unitUnit2;
interface
usesSysUtils,Windows,Dialogs,ExptIntf;
type
TMyExpert=class(TIExpert)
public
functionGetName:string;override;
functionGetAuthor:string;override;
functionGetComment:string;override;
functionGetPage:string;override;
functionGetGlyph:HICON;override;
functionGetStyle:TExpertStyle;override;
functionGetState:TExpertState;override;
functionGetIDString:string;override;
functionGetMenuText:string;override;
{LaunchtheExpert}
procedureExecute;override;
end;
implementation
{TMyExpert}
procedureTMyExpert.Execute;
begin
inherited;
ShowMessage(GetComment);
end;
functionTMyExpert.GetAuthor:string;
begin
Result:='ChrisMao';
end;
functionTMyExpert.GetComment:string;
begin
Result:='ThisisExpertDemo.';
end;
functionTMyExpert.GetGlyph:HICON;
begin
Result:=0;
end;
functionTMyExpert.GetIDString:string;
begin
Result:='ChrisMao.ExpertDemo';
end;
functionTMyExpert.GetMenuText:string;
begin
Result:='ClickMe';
end;
functionTMyExpert.GetName:string;
begin
Result:='ExpertDemo';
end;
functionTMyExpert.GetPage:string;
begin
Result:=EmptyStr;
end;
functionTMyExpert.GetState:TExpertState;
begin
Result:=[esEnabled];
end;
functionTMyExpert.GetStyle:TExpertStyle;
begin
Result:=esStandard;
end;
end.
interface
usesSysUtils,Windows,Dialogs,ExptIntf;
type
TMyExpert=class(TIExpert)
public
functionGetName:string;override;
functionGetAuthor:string;override;
functionGetComment:string;override;
functionGetPage:string;override;
functionGetGlyph:HICON;override;
functionGetStyle:TExpertStyle;override;
functionGetState:TExpertState;override;
functionGetIDString:string;override;
functionGetMenuText:string;override;
{LaunchtheExpert}
procedureExecute;override;
end;
implementation
{TMyExpert}
procedureTMyExpert.Execute;
begin
inherited;
ShowMessage(GetComment);
end;
functionTMyExpert.GetAuthor:string;
begin
Result:='ChrisMao';
end;
functionTMyExpert.GetComment:string;
begin
Result:='ThisisExpertDemo.';
end;
functionTMyExpert.GetGlyph:HICON;
begin
Result:=0;
end;
functionTMyExpert.GetIDString:string;
begin
Result:='ChrisMao.ExpertDemo';
end;
functionTMyExpert.GetMenuText:string;
begin
Result:='ClickMe';
end;
functionTMyExpert.GetName:string;
begin
Result:='ExpertDemo';
end;
functionTMyExpert.GetPage:string;
begin
Result:=EmptyStr;
end;
functionTMyExpert.GetState:TExpertState;
begin
Result:=[esEnabled];
end;
functionTMyExpert.GetStyle:TExpertStyle;
begin
Result:=esStandard;
end;
end.
注:这种从TIExpert继承,来编写Expert的方法,在Delphi6中已经被淘汰了(但这不表示这种方法不可用),取而代之的是使用Open Tools API方式实现。
版权声明:本文为博主原创文章,未经博主允许不得转载。
相关推荐
Expert Delphi.pdf
Tcomm控件编写Delphi串口调试程序,计算机串口通讯232测试系统,功能有测试端口、传送和接收文件、设置端口波特率、COM口选择,奇偶校验、字节长度设置、停止位选择、保存文件内容、测试通信口等。
Delphi Formatter Expert 2.5.6(支持XE3).rar
本文档并不意味着包含了所有存在于代码中的标准。但是,它的内容已足够帮你起个好头。你可以自由的增加修改这些标准来满足你的需要。我们不赞成你偏离这些由Borland开发人员所使用的标准太远。我们推荐这么做是因为...
Delphi Main menu expert
自己编写的Delphi组件定时器Timer,内支持线程,不会像D原生那样卡顿及界面.
Delphi Formatter Expert 2.5.6(支持XE3)
delphi编写的计算器,简单源码。。。。
Expert Delphi-Pawel Glowacki-Packt-20170630.epub 本书基于rad studio 10.2 tokyo
用delphi编写的记事本文件,包含常用功能
delphi编写的数据库连接测试 delphi编写的数据库连接测试
delphi编写的闹钟 delphi编写的闹钟
delphi 简单编写PING操作
delphi编写动态链接库Dll,附delphi调用dll的示例,包含dll的源码和调用dll的源码。
Delphi7组件编写者指南(pdf格式)
Delphi编写组件扩展ASP的功能delphi源码 Delphi东进电话银行(主叫功能)
Delphi 程序员代码编写标准指南
如何用Delphi编写安装程序,详细方法