TypeCast com Interface

Delphi

24/07/2007

Tenho uma interface declarada da seguinte forma em um pacote.
IRegisterAddIn = interface
  [´{800EC0B0-3A4F-44D8-822A-9B4091148281}´]
  function GetName: string;
  function GetDescription: string;
  function GetAutoLoad: Boolean;
  function GetFullName: string;

  property Name: string read GetName;
  property Description: string read GetDescription;
  property AutoLoad: Boolean read GetAutoLoad;
  property FullName: string read GetFullName;
end;


Em outro pacote, tenho a seguinte declaração:
TClienteAddInRegister = class(TInterfacedPersistent, IRegisterAddIn)
private
  { Private declarations }
  function GetName: string;
  function GetDescription: string;
  function GetAutoLoad: Boolean;
  function GetFullName: string;
public
  { Public declarations }
  property Name: string read GetName;
  property Description: string read GetDescription;
  property AutoLoad: Boolean read GetAutoLoad;
  property FullName: string read GetFullName;
end;


E na minha aplicação, tenho o seguinte trecho de código:
var
  SearchRec: TSearchRec;
  RegisterAddIn: IRegisterAddIn;
  AClass: TPersistentClass;
begin
  if FindFirst(´*.bpl´, faArchive, SearchRec) = 0 then
  begin
    repeat
      PackageHandle := LoadPackage(SearchRec.Name);
      try
        AClass := FindClass(´TClienteAddInRegister´);
      except
        AClass := nil;
      end;

      if AClass <> nil then
      begin
      end; 
        
      if PackageHandle <> 0 then
        UnloadPackage(PackageHandle);

    until FindNext(SearchRec) <> 0;
  end;
end;


Essa minha aplicação so possui referencia direta ao primeiro pacote. Tem como eu criar o objeto a partir de AClass e fazer um cast com a interface IRegisterAddIn?


Rjun

Rjun

Curtidas 0
POSTAR