My own class has null manager. Why?  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

My own class has null manager. Why?

Postby DannyC » Sun Oct 13, 2019 8:45 am

See attached.
I'm creating my own class, inheriting ProcessAction.UserInterface.

I need to use manager because it will be interacting with the database, but when I test it, the manager is null.
I can't work out why, or how to get a proper manager object.

Version 7.2.1
Attachments
Plugin Load File test.xml
(30.63 KiB) Downloaded 46 times
User avatar
DannyC
Senpai
Senpai
 
Posts: 635
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 29

Re: My own class has null manager. Why?

Postby Mike.Sheen » Mon Oct 14, 2019 8:56 am

Hi Danny,

You're referencing the Manager in the constructor of the class:

Code: Select all
public ImportExceltest()
{
    System.Diagnostics.Debugger.Launch();
    JiwaFinancials.Jiwa.JiwaApplication.Manager manager = null;
...
}


This won't have it's Manager property set at that point.

You should override the Setup method and move your code there. Also make sure to call base.Setup(); as the first line of your overridden Setup method.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2440
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 755

Re: My own class has null manager. Why?

Postby DannyC » Mon Oct 14, 2019 9:23 am

manager is still null.

Code: Select all
partial class ImportExceltest : JiwaFinancials.Jiwa.JiwaApplication.ProcessAction.UserInterface
{
   JiwaFinancials.Jiwa.JiwaApplication.Manager manager = null;
   
   public override void Setup()
   {
      base.Setup();
      manager = base.Manager;      
   }
   
   public ImportExceltest()
   {
      System.Diagnostics.Debugger.Launch();
      System.Windows.Forms.OpenFileDialog fileOpenDialog = new System.Windows.Forms.OpenFileDialog();      
       fileOpenDialog.Filter = "Excel Spreadsheets (*.xls;*.xlsx)|*.xls;*.xlsx";
      if (fileOpenDialog.ShowDialog(manager.MDIParentForm) == System.Windows.Forms.DialogResult.OK)
      {
         this.New(fileOpenDialog.FileName);
         
      }      
   }

   public void New(string filename)
   {
      MessageBox.Show(filename);
   }
   
   
}
User avatar
DannyC
Senpai
Senpai
 
Posts: 635
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 29

Re: My own class has null manager. Why?  Topic is solved

Postby Mike.Sheen » Mon Oct 14, 2019 9:27 am

Hi Danny,

Don't set the Manager - we'll do that in the factory that creates the class.

Also don't declare your own manager - the base class already has one!

This, I believe, is what you are looking for:

Code: Select all
partial class ImportExceltest : JiwaFinancials.Jiwa.JiwaApplication.ProcessAction.UserInterface
{
   public override void Setup()
   {
      base.Setup();
      System.Diagnostics.Debugger.Launch();      
      System.Windows.Forms.OpenFileDialog fileOpenDialog = new System.Windows.Forms.OpenFileDialog();      
       fileOpenDialog.Filter = "Excel Spreadsheets (*.xls;*.xlsx)|*.xls;*.xlsx";
      if (fileOpenDialog.ShowDialog(Manager.MDIParentForm) == System.Windows.Forms.DialogResult.OK)
      {
         this.New(fileOpenDialog.FileName);
         
      }      
   }

   public void New(string filename)
   {
      MessageBox.Show(filename);
   }   
}
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2440
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 755

Re: My own class has null manager. Why?

Postby DannyC » Mon Oct 14, 2019 9:52 am

YES!!!!!!!!

Thanks Mike. Phew, that's such a relief to get some working code!
User avatar
DannyC
Senpai
Senpai
 
Posts: 635
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 29


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 5 guests

cron