Question Problem creating and disposing classes

oliverg

Active member
Joined
Apr 14, 2010
Messages
37
Programming Experience
1-3
Hi,

How can I dynamically initiate a "new" class?

Basically I'm storing references to classes in an array and I want to create and dispose them on demand.

Is there a way to store class references and use the reference to initiate a new class?
 
What you're asking for doesn't really make sense to me. Are you saying that you want to have an array that contains, say, DataTable, Form and StreamReader, and then you want to be able to get one of those classes from the array and use it to create instances of that type? That is a rather unusual request so I'm guessing that one of us is misunderstanding something. Can you provide a more complete description of exactly what you're trying to achieve and, importantly, why you're trying to achieve it? If we understand the motivation then we can provide the best advice, which might be to do things a very different way.
 
Hi,

Sorry for the vague question. I think I'm looking for a solution to a problem caused by my inexperience on this kind of thing.

I could easilly hard-code all of this, but I'm trying to keep it dynamic as this will be a template project. not only this, but the way I'd like to do it will help reduce resource wastage during my application run time.

I have a tab control, which I can add and remove tab pages from (identified using the tabpage.text attribute)

The tab pages that I am adding are just blank, they get their name from the toolstripmenuitem that is used to select or deselect the tab.

I have an array of modified toolstripmenuitems that fills the toolstrip. The modification is an extra property called panel.

I assign a class to this property that derives from an abstract class. the abstract template inherits a panel and allows me to set up a GUI for performing a set group of tasks.

I don't want all of the panels to be continually active in the background, as events will cause unneccecary activity.

I can't initiate a new panel each instance, because the calling code is accessing the panel attribute through the modified toolstripmenuitem array.

Really, I need to start again, I think there must be a better way of doing this.
 
I think I'm just going to extend the click event in my modified toolstripitem class so that when the tab is created it will call a typed event handler for each item.
 
Im going to do this for each toolstripmenuitem:

Private WithEvents stripItem As New dynamicTabPage.dtpMenuItem
Public Sub New()
stripItem.Text = "working..."
stripItems(0) = stripItem
End Sub
Private Sub stripItem_panelCreated() Handles stripItem.panelCreated
stripItem.Panel = New homeTPA 'I'll change this for each toolstripitem End Sub
Private Sub stripItem_panelDisposed() Handles stripItem.panelDisposed
stripItem.Panel.Dispose()
End Sub

Then add to my array:

Public stripItems(0) As dynamicTabPage.dtpMenuItem

Then use that array in my generic calling class.
 
Back
Top