Page 1 of 1

My own class has null manager. Why?

PostPosted: Sun Oct 13, 2019 8:45 am
by DannyC
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

Re: My own class has null manager. Why?

PostPosted: Mon Oct 14, 2019 8:56 am
by Mike.Sheen
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.

Re: My own class has null manager. Why?

PostPosted: Mon Oct 14, 2019 9:23 am
by DannyC
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);
   }
   
   
}

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

PostPosted: Mon Oct 14, 2019 9:27 am
by Mike.Sheen
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);
   }   
}

Re: My own class has null manager. Why?

PostPosted: Mon Oct 14, 2019 9:52 am
by DannyC
YES!!!!!!!!

Thanks Mike. Phew, that's such a relief to get some working code!