Jump to content

MainModule Package BPL Instance


herculanojs

Recommended Posts

I need to access the MainModule instance of forms being bundled into bpl.
I can not make implicit reference to MainModule in the form that will be inside the bpl.
Where can I get the instance of MainModule?
 
UniApplication.UniMainModule_ ???
UniApplication.UniMainModule ???
 
 
procedure TMainForm.UniButton1Click(Sender: TObject);
var Form:TUniform;
    PercClasse:TPersistentClass;
begin
     //TUniForm
     PercClasse:= GetClass('TUniForm');
     if PercClasse = nil then
        LoadPackage('Package1.bpl');
 
     PercClasse:= GetClass('TUniForm');
     if PercClasse <> nil then
     begin
          Form := TUniFormClass(PercClasse).Create(UniApplication);
          if ExecutaMetodo(form,'prepara1') then
             Form.Show();
     end;
end;
 
IN FORM BPL
 
procedure TUniForm1.UniButton1Click(Sender: TObject);
begin
     //MainMudule ?? GetValue and objects
end;

 

unigui bpl.rar

Link to comment
Share on other sites

When you create the form, you pass UniApplication as the Owner.

 

As you can see in the MainModule, the function locating it at run-time is:

 

function UniMainModule: TUniMainModule;
begin
  Result := TUniMainModule(UniApplication.UniMainModule)
end;
 
In your form, you have access to UniApplication:
 
Self.UniApplication
 
So, if you need to access the MainModule, use:
 
TUniMainModule(Self.UniApplication.UniMainModule)
Link to comment
Share on other sites

TUniGUIMainModule(Self.UniApplication.UniMainModule)

 

Just by correcting, you should use the class TUniGUIMainModule and not TUniMainModule.

For the second makes an implicit reference to the object that would be unknown in the unit of the bpl, consequently would require the uses of the class of its origin.

 

 

type
  TUniMainModule = class(TUniGUIMainModule)
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...