[.net] C# MDX....Why can't I see the DX device?

Started by
1 comment, last by GameDev.net 17 years, 4 months ago
I have code resembling the following: -------FILE1.CS---------- namespace Engine{ public class MainForm : System.Windows.Forms.Form{ public Device device; } } --------FILE2.CS-------- namespace Engine{ public class View{ View(){ ..... WHY CAN'T I ACCESS THE DEVICE FROM HERE? } } } How can I access Device declared in the Mainform class from the constructor of the View class? The Visual Studio Intellisense sees the Engine namespace and the MainForm class, but it seems to only show the members of the native Form class.
Advertisement
Well unless you make the device static, you're going to need an instance of the MainForm class. Unless there's something you're not showing us.
A second way, and one that I use more commonly than making things static, is that I'd write the FILE2.CS as:

namespace Engine{
public class View{

Device TargetDevice;
View(Device targetDevice)
{
TargetDevice=targetDevice;
}
}
}

Using this method, you will always have a pointer to the device, the only thing to pay attention to is that if you don't set the reference (TargetDevice) to null before discarding the object it is pointing to, you will keep both objects around, the View, and the TargetDevice.

This topic is closed to new replies.

Advertisement