result := GetPluginByIndex( index );
end;
function TPluginLoader.GetPluginByIndex( const index: integer ): IPlugin;
begin
Check( Index < FPluginList.Count,
IntToStr( index ) + ''超出范围 ,没有该索引.'' );
result := IPlugin(Pointer(FPluginList.Objects [index]));
end;
procedure TPluginLoader.LoadPlugin( const XmlFile: string );
var
BplFile : string;
XmlRoot : IXMLPluginType;
ImplClass : TPersistentClass;
obj : TPersistent;
Intf : IPlugin;
BplHandle : Cardinal;
begin
BplFile := ChangeFileExt( XmlFile, ''.bpl'' );
XmlRoot := Xmlplugin.Loadplugin( XmlFile );
//载入bpl
BplHandle := LoadPackage( BplFile );
//存入接口变量
ImplClass := GetClass( XmlRoot.Class_ );
check( ImplClass <> nil,
Format( ''没有在%s中找到%s类.'', [BplFile, XmlRoot.Class_] ) );
obj := ImplClass.Create;
Check( Supports( obj,
StringToGUID( ''{48BF4000-B028-4B57-9955-B1A8305DA394}'' ), Intf ),
ImplClass.ClassName + ''不支持插件接口IPlugin.'' );
//存入plugin,不允许id重复
if FPluginList.IndexOfName( XmlRoot.Id ) = -1 then
begin
FPluginList.AddObject( XmlRoot.Id + ''='' + IntToStr( BplHandle )
, Pointer(Intf) );
end;
end;
procedure TPluginLoader.LoadPlugins( Directory: string );
var
i : Integer;
begin
with TStringList.Create do
begin
try
Text := GetFilesList( Directory, ''.xml'' );
for i := 0 to Count - 1 do
&nbs