A plug-in framework to be developed for ApplicationsProgramProvides flexible plug-in support based on DLL/interface.
First, the previous Graph
This is a standard plug-in-based application. In the drop-down box, the functions provided by five plug-in DLL are provided. The main program defines an interface, and the plug-in DLL provides the implementation of this interface.
It's easy to use. Place a textensionmanager component in the window and set the plug-in's read path.
The framework has three important concepts: servicehost, module, and extension)
1. servicehost is the soul of the entire framework. It is used to query and use other plug-in objects in the main program or plug-in.
The following is an exampleCode:
(Servicehost as iloggingservice). Log ("this is a log ");
(Servicehost as iparameterservice). setvalue ("param1", "value1 ");
(Servicehost as imyplugin). Foo ();
(Servicehost as imyextension). Execute ();
2. module is the container of extension, that is, a module contains multiple extension. In fact, the module does not provide any functions, nor does it provide extension management functions. It only provides logical grouping for extension and group-related information for applications. A plug-in dll can contain multiple modules.
3. extension is the extension object management class. When a class implements the plug-in interface, it is released through this object and its lifecycle is managed by this object.
In addition, the framework also provides some common services, which also exist as plug-ins. The above iloggingservice and iparameterservice
Iparameterservice
Parameter service, which provides parameter support for applications and extensions, such as $ (apppath)
Iregistryservice
Registry Service for storing and reading information
Iloggingservice
Log service outputs messages to different locations through channels
Ichannel
Log channel used to output messages to a specified location
Ilocalizationservice
Localization service, used to provide localized Resources
Ilocalesource
Localized Service Data Source
Isplashservice
The pop-up screen service is used to access the pop-up window.
Idialogservice
Dialog Box Service, used to provide various dialogs
Iloginservice
Logon service, used to control user logon
Paste a few more demo images.
Sample Code:
View code
// Main program
Unit Umodule;
Interface
Implementation
Uses
Eftoolservices, efmodule, efwinregistry, eflogging, efparameter;
Initialization
Tinterfaceextension. Create (iregistryservice, twindowsregistryservice. Create,
' 2011.08.11 ' , ' Registryservice ' , ' Iregistryservice provider ' , ' Author: sephil ' );
Tinterfaceextension. Create (iloggingservice, tloggingservice. Create,
' 2011.08.11 ' , ' Loggingservice ' , ' Iloggingservice provider ' , ' Author: sephil ' );
Tinterfaceextension. Create (iparameterservice, tparameterservice. Create,
' 2011.08.11 ' , ' Parameterservice ' , ' Iparameterservice provider ' , ' Author: sephil ' );
End .
View code
// Plug-in
Unit Udllimpl;
Interface
Implementation
{$ I efdef. inc}
Uses
Efexports,{Export DLL entry proc}
Efsystem, eftoolservices, efmodule, efsysutils,
Udocintf, windows, messages, sysutils;
Type
Tdllobject =Class(Tinterfacedobject, idlobject)
Private
ProcedureExecopen;
ProcedureExecinsert (canundo: Boolean );
End;
Tdllmodule =Class(Tmodule)
Protected
Class FunctionInitializecomponents (HOST: iinterface): integer;Override;
ProcedureUpdatedesctiption;Override;
Public
ProcedureInitialize;Override;
ProcedureFinalize;Override;
End;
{Tdllobject}
ProcedureTdllobject. execopen;
VaR
S: widestring;
Begin
(ServicehostAsIparameterservice). getvalue ('$ (Apppath)', S );
S: = S +'\ Textdoc.txt';
(ServicehostAsIdocument). Open (s );
End;
ProcedureTdllobject. execinsert (canundo: Boolean );
VaR
S:String;
Begin
S: = formatdatetime ('C', Now );
Sendmessage (servicehostAsIdocument). gethwnd,
Em_replacesel, wparam (canundo), lparam (pchar (s )));
End;
{Tdllmodule}
FunctionGetmodule:String;
Begin
Setstring (result,Nil, Max_path );
Setlength (result, getmodulefilename (hinstance, @ result [1], Max_path ));
End;
Class Function Tdllmodule. initializecomponents (HOST: iinterface): integer;
VaR
S: widestring;
Begin
(Servicehost As Iloggingservice). Write ( ' Tdllmodule. initializecomponents ' );
(Servicehost As Iparameterservice). getvalue ( ' $ (D2007) ' , S );
If { $ Ifdef delphi12_up } Not { $ Endif } Strtobool (s) Then Result: = 0 Else Result: = 1 ;
If Result <> 0 Then
(Servicehost As Iloggingservice). Write (extractfilename (getmodule) +' Skipped ' )
Else
(Servicehost As Iloggingservice). Write (extractfilename (getmodule) + ' Loaded ' );
End ;
ProcedureTdllmodule. updatedesctiption;
Begin
// Original info from version info
Inherited;
End;
ProcedureTdllmodule. initialize;
VaR
INTF: iloggingservice;
Begin
Inherited;
(ServicehostAsIloggingservice). Write ('Tdllmodule. initialize');
End;
procedure tdllmodule. finalize;
begin
inherited ;
(servicehost as iloggingservice ). write ( ' tdllmodule. finalize ');
end ;
Initialization
Registermoduleclass (tdllmodule );
Textensionfactory. Create (idlobject, tdllobject,'2011.08.08',
'DLL object','Idlobject implementation','Author: sephil');
End.