Dyalog Primer - User Interfaces - Forms
Explorationf←⎕new 'Form' (('Caption' 'Form Example')('Coord' 'Pixel')('Size' (400 400)))
f.l←f.⎕new 'Label' (('Caption' 'What''s your name')('Posn' (10 10))('Size' (20 100)))
f.e←f.⎕new 'Edit' (('Text' '')('Posn' (30 10))('Size' (20 100)))
f.howdy←f.⎕NEW'Label'(('Caption' '')('Posn'(60 10))('Size'(20 100)))
f.OK←f.⎕new 'Button' (('Caption' 'OK') ('Posn' (100 10))('Size' (25 100)))
f.Cancel←f.⎕NEW'Button'(('Caption' 'Cancel')('Posn'(100 110))('Size'(25 100)))
⊃ ⎕vrš'SayHowdy' 'SelectOK' 'SelectCancel'
∇ form SayHowdy msg
 ⍝ Echo back the input
∇ form SelectOK msg
 ⎕←'OK pressed'
∇ form SelectCancel msg
 ⎕←'Cancel pressed'
⍝ Type something into the edit box, then use the tab key to move the cursor
⍝ Repeat, using a different name
⍝ Click on either the OK or Cancel buttons
don't have to use forms to communicate between user and application,
but they're generally a good idea - and they make your application look
like most others.
- The form is created using APL/W
Version 11 syntax (there's an older syntax described in the
are a few (mostly undocumented) anomalies in the new syntax - for
example, needing the onEvent callbacks to be defined on a separate line
from the main control specifications.
- Notice the
relationship between the form and the callback functions; you can
easily get yourself into quite a messy workspace unless you're
disciplined. That's where namespaces (as a way to partition
workspace into neat little parcels) are so very useful. A
rule of thumb is that you should have no more than one form per
- Passing the form as left argument into
functions is a good way of tying your code together (giving it greater
cohesion - in one of the parlances).
- Modal forms
when you need to force your user to deal with one thing at a time, but
in general are best avoided - allowing the user greater
- Notice the style of form
behaviour here -
respond immediately to user input (here, tabbing out of the edit
control) - use OK and Cancel buttons to collect (validated) input and
determine what the user wants you to do next.
an interactive form design tool (similar to those you find in Visual
Studio) which you may like to explore, most people seem to prefer
hand-crafting their forms (and staying within APL rather than trying to
use externally-created forms).
- Dyalog Interface Guide
- Chapter 2; GUI Tutorial
- Chapter 4, Composite Controls
- Chapter 5, Hints and Tips
- Chapter 6, Using the Grid object
- Chapter 7, MDI Applications
- Chapter 8, Docking
- Dyalog Object Reference
a function which defines a form with an Edit control, a Combo and
OK/Cancel buttons. Populate the combo with the names of English
counties. Put this function into a namespace called
<forma>. When run it should wait (non-modally) for user
- Add a callback to check that what the user types into
the Edit control are only letters of the alphabet. If a
non-alphabetic character is typed in display a message box and reset
the control contents to only alphabetic characters.
- Write callbacks for the OK and Cancel buttons - these should remind the user which button they pressed and close the form.
File and Help menus to the form; the File menu should have a Close item
(closes the form), the Help menu should have an About item (shows a
modal message box with some text in it about these exercises).
your code so that the form is split into two resizeable subforms,
putting the Combo and Edit controls into one subform and the buttons
into the other.