MrJim wrote:
How should variables be declared and referenced in both the base and
derived form so they can be accessed?
You might try it this way
Declare all variables in a class as private.
If the variable needs to be access in derived classes, then provide a
protected property
e.g.
dim _conn as Connection
Protected Property Connection as Connection
...
end property
If the variable needs to be access outside the class and its
descendents then create a public property.
NOTE: In both of the above cases, you will probably want to access the
variable through the property even in the base class. Although you
have direct access to the variable it is useful to chokepoint all
access, e.g. if you want to raise an event when the value is changed.
Form specific:
By default, the IDE makes all control variables Friend.
This translates as 'public to other classes in the same assembly' which
can cause problems if you inherit from them in another assembly.
there are a number of choices here
1) make them protected
2) make them protected friend
3) Add wrapper functions/properties to access them
e.g.
if you have a listbox in the base class to which you want to add
items, then instead of directly access the listbox in the derived
class [mybase.listbox1.items.add(xxx)], in the base class create a
protected sub to do it for you
Protected Sub AddItem(w as widget)
Listbox1.Items.add(w)
end sub
why? Say, halfway through you decide that you want to use a treeview
instead of a listview, all you need change is the base class.
hth,
Alan.