I have an application that loads a BPL that as inside a simple form.
This form is an optional option of the main application.
The BPL loads correctly, the form is shown correctly, but I don’t know how to access the public methods and properties of the form inside the bpl.
Can anyone provide a simple example?
my code:
// Load the BPL on aplication Load
LoadPackage( 'About.bpl' );
// CAll for TForm1 inside the About.BPL
var
AClass: TClass;
AForm: TForm;
begin
AClass := GetClass('TForm1');
if AClass <> nil then
begin
Application.CreateForm(TComponentClass(AClass), AForm);
AForm.Show;
end;
// The unit TForm1 inside the BPL package
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
PublicMthd;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
Procedure TForm1.PublicMthd;
Begin
ShowMessage('Inside call');
End;
initialization
RegisterClass(TForm1);
finalization
UnRegisterClass(TForm1);
end.
How can i access "PublicMthd" in Tform1 ?
function GetMainForm:TForm
and then you can access it? Is there a reason you can't use a common sense approach? What do you intend to do once you know the classes and can enumerate them, and perhaps even create instances of them? Is there a reason you aren't specifying an IPluginInterface that fits your problem domain, instead of going directly to the underlying class types, from your main application? – Reduced