forms - How to get available classes at runtime -
i poll class , have return available subclasses in way can address them. can return array, dictionary, or else. long can loop through set of them , read properties or call functions each.
scenario: want create form user inputs details of series of events. read form , output report. each kind of event has ".name", different set of inputs (formoptions) , methods (formatoutput) create output. right implemented complex form , script runs after user submits form.
the trouble every time add option form, have change code in several different places. in interest of making code easier maintain, contain code each event type in class, build form based on available classes.
so example, i'm building itinerary collection of meeting , travel objects:
class itinerary class event public property name() name = "meeting" end property public function formoptions(id) form options = "<div id="& id &">form code meeting options</div>" end function public sub formatoutput(time, title, location) 'make fancy meeting entry end sub end class class travel public property name() name = "travel" end property public function formoptions(id) form options = "<div id="& id &">form code travel options</div>" end function public sub formatoutput(starttime, endtime, origin, destination) 'make fancy travel entry end sub end class end class
when script runs creates form user can add series of events. each time user chooses between "meeting" , "travel" fills out options event type. @ end, push button , script makes pretty document listing user's inputs.
at point in future, want add new kind of event: lodging.
class lodging public property name() name = "lodging" end property public function formoptions(id) form options = "<div id="& id &">form code lodging options</div>" end function public sub formatoutput(date, location) 'make fancy lodging entry end sub end class
how setup itinerary class automatically recognizes new class , can return available event type? can think of several ways of doing this, involve keeping index of available classes separate actual classes, , i'm trying minimize number of places have change code when add new event types.
i purposely not including details on how build form since @ point i'm open anything. also, please gentle references "inheritance", "extensibility", or "polymorphism". i'm scripter , these oop concepts still bit foreign me.
i don't think possible, 1 way come close have unique list of class names -- simplest have global dictionary.
you can list of classes reading keys
collection of dictionary.
i don't think vbscript supports references classes, when user chooses 1 of types use eval
create instance of appropriate class.
dim classlist set classlist = createobject("scripting.dictionary") 'on type selection: function getitineraryinstance(classname) set getitineraryinstance = eval("new " & classname) end function classlist("travel") = 1 class travel 'methods end class
at least class registration can kept class definition.
Comments
Post a Comment