Compile Delphi expert by yourself

Source: Internet
Author: User

At the beginning of the programming stage, I was very excited to write a login form step by step, or a form that could add, delete, or modify data table records. However, as programming time and writing projects increase, we will find that such forms with no technical content are repeatedly written, as a result, is there a permanent way to help us get rid of this dilemma? Some friends may say that they make a standard form and store it in a landlord, copy it as needed, and then slightly modify it. It is undeniable that this is also a method, but for a programmer, this method is not very professional. The other side is relatively more professional, that is, writing an expert by yourself.

Delphi is a fully open development and integration environment. It provides a set of toolsapis for developers to expand (the relevant units are in the source/toolsapi/directory of the installation directory of Delphi ). To compile your own expert, you need to reference the exptintf. Pas file, which defines an abstract base class tiexpert. Any custom expert must inherit from it.

Tiexpert = Class (tinterface)
Public
... {Expert UI strings}
Function getname: string; virtual; stdcall; abstract;
Function getauthor: string; virtual; stdcall; abstract;
Function getcomment: string; virtual; stdcall; abstract;
Function getpage: string; virtual; stdcall; abstract;
... {$ Ifdef mswindows}
Function getglyph: hicon; virtual; stdcall; abstract;
... {$ Endif}
... {$ Ifdef Linux}
Function getglyph: Cardinal; virtual; stdcall; abstract;
... {$ Endif}
Function getstyle: texpertstyle; virtual; stdcall; abstract;
Function getstate: texpertstate; virtual; stdcall; abstract;
Function getidstring: string; virtual; stdcall; abstract;
Function getmenutext: string; virtual; stdcall; abstract;

... {Launch the expert}
Procedure execute; virtual; stdcall; abstract;
End;

The following describes the methods in this class.

Method Name Description
Getname Subclass must rewrite this method to specify a unique name for expert
Getauthor If form export or project expert is written, the subclass must rewrite this method and assign the author to the expert. This string will appear in Object repository.
Getcomment If form export or project expert is written, the subclass must rewrite this method to briefly describe the usage of expert.
Getpage If form export or project expert is written, the subclass must rewrite this method to specify the page on which the expert appears in the new item form.
Getglyph If you are writing form export or project expert, the subclass must rewrite this method, specify the icon displayed by the expert in the new item form, and return 0 to indicate that the default icon is used.
Getstyle The subclass must override this method and specify the expert type. Only one of the following four values can be taken: esstandard, esform, esproject, esaddin
Getstate If standardexport is written, the subclass must rewrite this method to specify the expert menu status displayed in help.
Getidstring Subclass must override this method to provide a string that does not conflict with any other expert. By convention, the string format is companyName. expertfunction
Getmenutext If you are writing standard export, the subclass must rewrite this method to specify the title of the "expert" menu displayed in help.
Execute If you are writing standard export, form export, or project expert, the subclass must rewrite this method. This method is executed when you click the menu or the "expert" icon in the new item.

The demo below will add a menu item in the Help menu of Delphi ide. After clicking it, a dialog box will pop up showing "this is expert demo .".

Unit unit2;

Interface

Uses sysutils, windows, dialogs, exptintf;

Type
Tmyexpert = Class (tiexpert)
Public
Function getname: string; override;
Function getauthor: string; override;
Function getcomment: string; override;
Function getpage: string; override;
Function getglyph: hicon; override;
Function getstyle: texpertstyle; override;
Function getstate: texpertstate; override;
Function getidstring: string; override;
Function getmenutext: string; override;

... {Launch the expert}
Procedure execute; override;
End;

Implementation

... {Tmyexpert}

Procedure tmyexpert. Execute;
Begin
Inherited;
Showmessage (getcomment );
End;

Function tmyexpert. getauthor: string;
Begin
Result: = 'chrismao ';
End;

Function tmyexpert. getcomment: string;
Begin
Result: = 'this is an expert demo .';
End;

Function tmyexpert. getglyph: hicon;
Begin
Result: = 0;
End;

Function tmyexpert. getidstring: string;
Begin
Result: = 'chrismao. expertdemo ';
End;

Function tmyexpert. getmenutext: string;
Begin
Result: = 'click Me ';
End;

Function tmyexpert. getname: string;
Begin
Result: = 'expertdemo ';
End;

Function tmyexpert. getpage: string;
Begin
Result: = emptystr;
End;

Function tmyexpert. getstate: texpertstate;
Begin
Result: = [esenabled];
End;

Function tmyexpert. getstyle: texpertstyle;
Begin
Result: = esstandard;
End;

End.

Note: This method, inherited from tiexpert, to compile the expert method, has been eliminated in DELPHI6 (but this does not indicate that this method is not available), instead, it is implemented using open tools api.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.