
A1.5 Adding a user-friendly interface with Visual C
++
11
print(vscore);
}
.......................................................................................
A mistake in the callback function is handled in the same way as other Ox errors.
For example, when changing vP[1] to vP[3] in dRosenbrock:
Runtime error: ’[3] in matrix[1][2]’ index out of range
Runtime error occurred in dRosenbrock(16), call trace:
C:\ox\dev\windows\callback\callback.ox (16): dRosenbrock
Runtime error: in callback function
Runtime error occurred in main(29), call trace:
C:\ox\dev\windows\callback\callback.ox (29): main
A1.5 Adding a user-friendly interface with Visual C
++
Ox is limited in terms of user interaction, only providing console style input using the
scan function. It is possible, however, to use much more powerful external tools to
add dialogs and menus. In that way, a much better interface could be written than ever
possible directly in Ox. Indeed, there are no plans to make interface components an
intrinsic part of Ox: this would always lag behind the latest developments.
Various approaches could be considered to add a user interface:
(1) Write a separate program which creates an input file.
(2) Write a separate program which generates an Ox source file.
(3) Write a DLL which exports dialogs to be used in Ox source code.
(4) Call Ox source code from an interactive program.
The first two approaches are the most simple, and can be used if the code is ‘uni-
directional’ (i.e. input is collected, then the program is run). Approach (2) is taken
by PcNaive: it collects user input on Monte Carlo design, generates an Ox program
from this, and calls OxRun to run the generated code. It can also retrieve settings from
previously generated source code, to produce a sophisticated interactive package.
The remaining two approaches are more appropriate if the program must be truly
interactive, or when further interaction is based on the result of computations. Examples
in the next two sections use method (4). An application called RanApp is developed.
This offers a set of actions and a dialog to change settings. Each action results in an Ox
function being called. It is RanApp which is in control of the Ox run-time system; in
method (3) that would be the other way round.
The examples below use Visual C
++
and Visual Basic (§A1.6). Java could also be
considered. A key requirement is that the tool can make calls to C functions residing in
the Ox DLL.
The knowledge from the previous sections already suffices to write an interface us-
ing FOxCallBack. There is, however, a second form of simplified callbacks which calls
a function by its text name. This method does not allow for arguments, and bypasses
the main function. The RanApp example in this section uses the simplified method,
and adds additional functions to be called from Ox to get dialog driven input.
Commentaires sur ces manuels