📄 global.pas
字号:
unit Global;
interface
uses
Windows, SysUtils, Classes, Forms, Dialogs;
type
TPlugIn = class(TObject)
PlugInID: string;
PlugInName: string;
PlugInFile: string;
end;
TProc = procedure(); stdcall;
TAddInsFactory = procedure(var PlugInInfo: Pchar);stdcall;
TShowForm = function (MainForm:TForm):TForm;stdcall;
procedure LoadPlugIns(); //装载插件集
procedure LoadPlugIn(sr:TSearchRec); //装载插件
procedure RunPlugIn(PlugInFileName:string); //运行插件
procedure ShowFormToPanel();
var
lstPlugIn: TList; //先用lstPlugIn的目的是为了方便以后更改主界面时不用修改插件
PlugIn: TPlugIn;
ShowForm : TShowForm;
CloseForm : TProc;
i: integer;
tmpForm:TForm;
implementation
uses MainFrm;
procedure LoadPlugIns();
var
sr: TSearchRec;
Path: string;
Found: Integer;
cPLUGIN_MASK :string;
begin
cPLUGIN_MASK := '*.dll'; //以扩展名dll为插件后缀
Path := ExtractFilePath(Application.Exename) + '\AddIns\' ; //插件存放的目录
try
Found := FindFirst(path + cPLUGIN_MASK, 0, sr);
while Found = 0 do begin
LoadPlugin(sr);
Found := FindNext(sr);
end;
finally
FindClose(sr);
end;
end;
procedure LoadPlugIn(sr: TSearchRec);
var
LibHandle: Integer;
AddInsFactory: TAddInsFactory;
FileName: string;
PlugInName: Pchar;
Describe: Pchar;
StatType: Pchar;
begin
FileName := ExtractFilePath(Application.Exename) + 'AddIns\' + sr.Name;
LibHandle := LoadLibrary(PChar(FileName));
if LibHandle <> 0 then
begin
PlugIn := TPlugIn.Create;
inc(i);
PlugIn.PlugInID := inttostr(i);
PlugIn.PlugInFile := sr.Name;
AddInsFactory := GetProcAddress(LibHandle,PChar('PlugInName'));
if Assigned(AddInsFactory) then
begin
AddInsFactory(PlugInName);
PlugIn.PlugInName := PlugInName;
end;
lstPlugIn.Add(Pchar(PlugIn));
end;
{释放}
AddInsFactory := nil;
FreeLibrary(LibHandle);
end;
procedure RunPlugIn(PlugInFileName:string);
var
LibH: Integer;
RunPlugIn: TProc;
FileName: string;
begin
FileName := ExtractFilePath(Application.Exename) + 'AddIns\' + PlugInFileName;
LibH := LoadLibrary(PChar(FileName));
if LibH <> 0 then
begin
ShowForm := GetProcAddress(LibH,PChar('ShowForm'));
CloseForm := GetProcAddress(LibH,PChar('CloseForm'));
if Assigned(ShowForm) then
ShowFormToPanel();
end;
end;
procedure ShowFormToPanel();
var
H:THandle;
R : TRect;
begin
if Assigned(ShowForm) then
with MainForm do begin
tmpForm:=ShowForm(MainForm);
H := pnlStat.Handle;
tmpForm.ParentWindow := H;
GetWindowRect(H, R);
OffsetRect(R, -R.Left, -R.Top);
tmpForm.BoundsRect := R;
tmpForm.Show;
end;
end;
initialization
lstPlugIn := TList.Create;
i := 0;
finalization
while lstPlugIn.Count<>0 do
begin
PlugIn := lstPlugIn.Items[0];
PlugIn.Free;
lstPlugIn.Delete(0);
end;
lstPlugIn.Free;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -