1

I'm trying to create a new module in SAP B1 SDK with visual studio (C#), and I have those variables inside the main class :

public static SAPbouiCOM.Application oApplication = null;
public static SAPbobsCOM.Company oCompany = null;
public static SAPbouiCOM.Form oForm = null;

and also in other classes I defined the same variables, so whenever I try to execute and get this error :

An unhandled exception of type 'System.NullReferenceException' occurred in MyFirsttest.exe
Additional information: La référence d'objet n'est pas définie à une instance d'un objet.

I would like to know if their is any way to define those variables once and for all, so I can use them in other classes.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Siham
  • 89
  • 1
  • 1
  • 4

1 Answers1

2

you should share the instance of the object, not the object itself. If you create an add-on, the company is already instanced, so you should rather fetch that.

Below the code to get the company in an add-on (what I suppose you create given the variables you mentioned).

oCompany = (SAPbobsCOM.Company)Application.SBO_Application.Company.GetDICompany()
Karl
  • 45
  • 4