herculanojs Posted October 29, 2017 Share Posted October 29, 2017 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 Quote Link to comment Share on other sites More sharing options...
davidizadar Posted October 30, 2017 Share Posted October 30, 2017 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) Quote Link to comment Share on other sites More sharing options...
herculanojs Posted October 30, 2017 Author Share Posted October 30, 2017 tanks Quote Link to comment Share on other sites More sharing options...
herculanojs Posted October 31, 2017 Author Share Posted October 31, 2017 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) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.