2

Short version: A class is being used without a variable of it's type being instantiated. How?

I have a huge legacy program which was converted from VB6 to VB.net. It is compiling and many aspects work, but there is a problem related to an MDI (Multiple-Document Interface) display. I have placed other test forms under the parent MDI form, and they display correctly. The form in question does not display. (And, of course, it is the MOST important, and a most intricately complex form. I wish I could re-write it, but there is no possibility of that.)

There is a class, MDI1, which is used over 7,000 times in the code by many, many other classes. The MDI1 class is used extensively in the form which does not display. Wherever MDI1 is used, it is always referred to as simply MDI1 or Namespace.MDI1 . As far as I can tell, it is never instantiated as an object. It is as though it is a singleton, somehow, but I see nothing making it one.

The header for the class follows:

Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class MDI1
  Inherits System.Windows.Forms.Form
  Dim MDI_Activated As Boolean

  Public Sub New()
    MyBase.New()
    InitializeComponent_Renamed()
  End Sub
  ...

Can anyone tell me what may be going on here?

Every place where it is used that I've tried to check in Visual Studio by right clicking and selecting "go to definition" takes me right back to the class definition (line 4 of the above code), and never to a variable of type MDI1. I have searched the entire source (using both Visual Studio and grepwin outside of Visual Studio) and can find no variable instantiated with type MDI1.

I don't understand how the calls to the class are working, without a variable of that type.

Help would be greatly appreciated.

I am using Visual Studio 2010 Professional, the latest version to which I have access.

Chris Dunaway
  • 10,974
  • 4
  • 36
  • 48
Mark T
  • 3,464
  • 5
  • 31
  • 45
  • are you looking for `static class` –  Aug 05 '15 at 05:36
  • The links were interesting and helpful. Thanks! (But just to be clear, the responses to the other two questions do, indeed, answer my question. However my question is NOT a duplicate. I asked IF such a thing were possible. The other two knew default instances existed and just wanted more info about them.) – Mark T Aug 05 '15 at 15:25

1 Answers1

5

I am assuming that you are not aware of Default Form Instance in VB.NET and hence the surprise. Its a common problem since this is missing in C#.

For winforms application in VB.NET, each form has a default instance and can be referred to simply by its form name (class name). You can ofcourse create your own instances like any other class and choose not to use the default instance.

This feature is particularly useful for legacy applications that have been migrated from VB6 to VB.NET since default form instance was a norm in VB6.

You can read more about Default Form Instances here:

https://msdn.microsoft.com/en-us/library/ms233839.aspx

And

https://msdn.microsoft.com/en-us/library/aa289529(v=vs.71).aspx

Pradeep Kumar
  • 6,836
  • 4
  • 21
  • 47
  • 1
    You are correct, I was totally unaware of Default Instances. (It may be a default instance of the complex form I mentioned in the question which is causing my problems.) Now that I know that Default Instances exist, I'll study to see how they affect my overall program. Thanks. – Mark T Aug 05 '15 at 15:32