Delphi
Open
Tools
API instance research (2)
First knowledge:
Delphi
/interface
/
DLL
/
COM (Understanding)
From:
http://dev.9cbs.net/develop/Article/21/21725.shtm
Difficulty: ★★ ☆☆☆
Before you start, you will say some questions, this time has been very busy (immediately at the end of the final exam, and the worst is now busy preparing the upcoming English.
Level 4 examine, so I don't know if this article is not enough. The content of this article may not be too much, but I still have to write it out as us.
Delphi
Open
Tools
API Example Research (2). In addition, I found some very nice about this information and websites, and I recommend it to everyone after I will.
Remember the last instance study one? We showcase an expansion of assembly packages by design
Example of Delphi. We will still be a practical meaning this time.
The Delphi plugin, the menu is still the same as the last last time, but this time is not the last source file inserted into a line of code, but add a development document to the current project, and is displayed
Delphi's code editor is provided to developer modifications. (At the same time, it is also saved in the directory where the project file is located). However, this time has a big difference with the last time, it is also the most important place to say: we will compile this plugin into
DLL, instead of the last component package, which provides an opportunity to create a more humane plug-in installer (instead of using a component package to install itself).
Let's take a look at this key point, we have established a dynamic connection library project and implements our plugin classes within the first unit file. Unlike the last time, we don't use traditional component registration processes.
REGISTER, but defines a type in unit class
The global function of TwizardinitProc, and in the project file
WizardEnTryPoint name export (Note: This name must be used.)
Exports
INITNEWMENU
Name
WizardEnTryPoint
;
Below is the original shape and implementation of this function in the unit:
FUNCTION
INITNEWMENU
(
Const
BorlandIDeServices
:
IborlandIDeServices
;
RegisterProc
:
TwizardRegisterProc
;
VAR
Terminate
:
TwizardterminateProc
):
Boolean
;
Stdcall
;
// registerproc: twizardregisterProc; parameter is used to create a wizard, in fact, this initialization function is used to create a DLL
// The form of traditional wizard can pass a class instance that implements IoTawizard to the RegisterProc parameter for this time.
// Registered Wizard, like this registerproc (xxx.create). Here we only use this function as an entry point of the initialization DLL
// So did not use this function, but directly myntatest: = tntatest.create; additional var terminate parameter is used to release
// You can assign it to it in the wizard, you can give it a normal process type such as Terminate: = xxx; xxx is a procedure
// This process is called to release the resource when the IDE is exit. Note that this function must be instructing in STDCALL.
VAR
SVCS
:
Iotaservices
;
Begin
Result
: =
BorlandideServices <>
NIL
;
IF
Result
THEN
Begin
SVCS
: =
BorlandIDeServices
AS
Iotaservices
;
/ / Save the BorlandIDeServices pointer
Toolsapi
.
BorlandIDeServices
: =
BorlandIDeServices
;
/ / Set the Host Application handle of the DLL
Application
.
Handle
: =
SVCS
.
GetParenthandle
;
MYNTATEST
: =
TNTATEST
.
Create
;
end
;
end
;
In addition, I also used a new one.
OTA interface, mainly in the first event of menu items (we have completed the work to add a development document to the current project):
IotaActionServices, this is a quite useful interface, in
IDE running
BorlandIDeServices implementation can be used to complete
The call of various functions of IDE. Such as:
Closefile,
Openfile,
OpenProject,
Reloadfile,
Savefile. The role of these features can guess according to their name. I still want to use it.
The IoTaprojectOptions interface is written in the document file from the relevant information and configuration options of the current project, but it is not the result of ideal, which is only about the project.
Options string list. We may be able to study and work in the next article.
A series of interfaces related to Iotaproject. Below is the code generated by the document section (corresponding to the first menu event of the menu item):
Procedure
TNTATEST
.
AddDocumentTopro
(
Sender
:
TOBJECT
);
VAR
Templen
,
i
,
Temppos
:
Integer
;
Documentfile
:
Textfile
;
ModuleCount
:
Integer
;
Tempstring
,
MoudlefilePath
:
String
;
Begin
/ / Request IoTamoduleServices T interface
Supports
(
BorlandIDeServices
,
IotamoduleServices
,
MoudleService
);
ModuleCount
: =
MoudleService
.
ModuleCount
;
IF
ModuleCount
<>
0
THEN
// No file open
Begin
CurentMoudle
: =
MoudleService
.
CurrentModule
;
// Get the current file name, we can use it to get the project path
Tempstring
: =
CurentMoudle
.
Filename
;
// The following part uses to analyze strings and take out the path of the project.
i
: =
POS
(
'/'
,
Tempstring
);
Templen
: =
Length
(
Tempstring
);
Temppos
: =
i
;
While
i
<>
0
DO
Begin
Tempstring
: =
Rightstr
(
Tempstring
,
Templen
-
i
);
i
: =
POS
(
'/'
,
Tempstring
);
Templen
: =
Length
(
Tempstring);
Temppos
: =
Temppos
i
;
end
;
MoudlefilePath
: =
LEFTSTR
(
CurentMoudle
.
Filename
,
Temppos
);
IF
Supports
(
BorlandIDeServices
,
IotaActionServices
,
ACTIONSERVICES
)
THEN
Begin
Assignfile
(
Documentfile
,
MoudlefilePath
'DocumentFile.txt'
);
Rewrite
(
Documentfile
);
Try
Writeln
(
Documentfile
,
'project name:'
);
Writeln
(
Documentfile
,
'Project master program name:'
);
Writeln
(
Documentfile
,
'Project version number:'
);
Writeln
(
Documentfile
,
'project description:'
);
Writeln
(
Documentfile
,
'Project team members:'
);
Writeln
(
Documentfile
,
'Document establishment time:'
DateTimetostr
(
NOW
));
Finally
Closefile
(
Documentfile
);
end
;
/ Note, we use the OpenFile method of IOTAAAActionServices to open the document you have just saved.
ACTIONSERVICES
.
Openfile
(
MoudlefilePath
'DocumentFile.txt'
);
end
;
end
Else
Messagebox
(
IDEHANDLE
,
'There isn' '' 't Active Project.'
,
'DocuCreat'
,
MB_ICONWARNING
);
end
;
The rest of the code (such as
IDE Add menu, etc., similar to last time, we will not write it here, you can refer to the previous article (connection:
HTTP
: //www.9cbs.net/develop/read_article.asp? id = 21725), you can also give me a letter to get the code (the address is the same as the last time). Finally, when we complete the code, we can compile it into a DLL file. Now let's take a look at how we will install our plug-in: first quit Delphi, open the registry, open the value of a string type under the hkey_current_user / software / borland / delphi / 7.0 / excerts key, named the name of our plugin , The value of the value of the DLL that we compiles. Now restart Delphi, how, the plugin starts working. With this approach, I believe that we can easily create an installer and anti-installer for our plug-in (nothing more than a simple operational registry, when you launch Delphi again, and delete the value that has just been established in the registry, restart Delphi will find that the plugin has been uninstalled), making it more friendly to the user, or more convenient for our release. Finally, I will explain: About debugging the DLL plug-in instructions, I recommend not returning too much error during the encoding process (when the run is running), you will find that you will have to start the plug-in, turn off Delphi This is a quite annoying thing (it's marked), I suggest you first take the plug-in as a last component package form for testing and adjustment, so you don't have to restart Delphi, change it again when the migration is successful Finally, I recommend some of my recent discovered
OTA's quite good website and information:
Http://www.gexperts.org/opentools/ Here you will get an OTA FAQ, quite good. : //www.gexperts.org/opentools/ Here you will get an OTA FAQ, quite good. Http://www.tempeest-sw.com/opentools/ Some old versions of OTA information: //www.tempeest-sw.com/opentools/ Some old version of OTA information http://home.quicknet.nl/qn /prive/rapp/delphi/delphi.html OTA part of the interface related information and examples: //home.quicknet.nl/qn/prive/rapp/delphi/delphi.html OTA part of the interface related information and example http: // Www.frasersoft.net/program/ delphi's OTA Help Patch (Unofficial), but quite incomplete: //www.frasersoft.net/program/ delphi's OTA Help patch (unfair), but quite incomplete
Finally, I wish you all a happy new year.