Maptitude GISDK Help |
You can break up your dialog box code into two sections:
View: just the user interface items, such as buttons and popdown menus
Controller: all of the data and logic for carrying out the users' choices
The view is a dialog box resource with all of the work done with class macros. You can have different controller objects for different uses of the same dialog box design.
Normally, when you program a dialog box, any macro inside in a dialog box resource cannot be re-used outside of the dialog box. This is not a problem if you program a simple dialog box with a few lines of code. When you start programming a larger application, it is a good idea to write reusable code, and keep the code inside the dialog box resource to the bare minimum.
This can be accomplished easily using an object-oriented approach called the model-view-controller, where the data model, user interface, and control logic are three separate components; you can change one without having to change the others. The dialog box resource can be as thin and generic as you desire, by having all of the do clauses in t he dialog box items just invoke class macros of the controller object. For example:
// This dialog box only knows about user interface items, such as buttons
Dbox "My Dialog Box" (controller, arguments)
Button "Do Something" do controller.DoSomething(arguments) enditem
Button "OK" do controller.ApplyChanges(arguments) enditem
endDbox
// This class does not know anything about user interface items.
// It only knows about data and logic. It can be called from the dialog box,
// or it can be called by other modules in your application.
Class "NameSpace.YourController" (initial_data)
Init do
// Initialize
Enditem
Macro "DoSomething" (arguments) do
// Do something
Enditem
Macro "ApplyChanges" (arguments) do
// Do some computations and output data
Return(output_data)
Enditem
endClass
// In your application, you would then use the dialog box like this:
manager = CreateObject("NameSpace.YourController", initial_data)
output_data = RunDbox("My Dialog Box", manager)
One advantage of using objects and classes is that you can customize the behavior of a dialog box by passing it a different controller object, one that would inherit from the class "NameSpace.YourController"
but have completely different implementations of DoSomething() and ApplyChanges(). For example, you could have a single Locate by Address dialog box and two controller objects, one that implements locating addresses for the US and another for Italy.
©2025 Caliper Corporation | www.caliper.com |