home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / ULDIAL.ZIP / ULDIAL.DOC < prev    next >
Encoding:
Text File  |  1990-06-25  |  10.8 KB  |  256 lines

  1.      ╔════════════════════════════════════════════════════════════════╗
  2.      ║ Dialog Objects as Enhancements to Turbo Power OOP Professional ║
  3.      ║               New Communications Technology, Inc.              ║
  4.      ║                           Version 1.0                          ║
  5.      ║                       by John Poindexter                       ║
  6.      ║                         CIS 73717,3405                         ║
  7.      ║                          June 25, 1990                         ║
  8.      ║                       ┌───────┐┌────────┐                      ║
  9.      ║                       │ Ok    ││ Cancel │                      ║
  10.      ║                       └───────┘└────────┘                      ║
  11.      ╚════════════════════════════════════════════════════════════════╝
  12.  
  13. The main object of this unit is DialogBox, an object to display short messages
  14. or instructions, get user input if desired and exit using radio buttons. There
  15. is also a timeout provision so the box can be used for temporary messages that
  16. are to be displayed for a short period of time and then clear. The above logo
  17. is a simulation of what you will get.
  18.  
  19. Object hierarchy:
  20.  
  21.   [Root]              [Root]                         [Root]
  22.     DialogBox           [AbstractWindow]               [StringArray]
  23.                           [RawWindow]                    MStringArray
  24.                             [StackWindow]
  25.                               [CommandWindow]
  26.                                 [AbstractSelector]
  27.                                   EntryScreen
  28.                                 [PickList]
  29.                                   DialogPick
  30.  
  31. DialogBox although an immediate descendant of Root contains an EntryScreenPtr
  32. field and DialogPickPtr fields and uses MStringArray which adds a data field
  33. and method that keep track of the maximum string length of added strings.
  34.  
  35. DialogBox has an automatic sizing feature which is the reason for making it an
  36. immediate descendant of Root rather than EntryScreen.
  37.  
  38. The minimal statements to use DialogBox look like this:
  39.  
  40.         if not MyDialog.Init(1,30,2,20) then Exit;
  41.         with MyDialog do
  42.         begin
  43.           AddMessageString('This is a test of DialogBox.');
  44.           AddChoiceString('Ok Cancel');
  45.           AddHeader(' My Test ', heTC);
  46.           Process;
  47.           Code := GetLastChoice;
  48.           Done;
  49.         end;
  50.  
  51. Unit ULDial uses Unit ULRoot which is included in the archive. TESTDIAL.EXE is
  52. an interactive testing program that will give you an opportunity to try out
  53. DialogBox. Unit ULStatus contains a status handler I use for handling errors
  54. and general messages to the user which is based on DialogBox.
  55.  
  56. Constants.
  57. ==========
  58. ucULDial
  59.   Unit code for Unit ULDial.
  60.  
  61. scOk      = 0
  62. scCancel  = 1
  63. scRetry   = 2
  64. scTimeOut = 99
  65.   Status codes which may be used for exit status of DialogBox.
  66.  
  67. Variables.
  68. ==========
  69. ULRootColorSet
  70.   This is initialized to ULColorSet which is in ULRoot.
  71.  
  72. Miscellaneous error codes and error messages are in ULRoot.
  73.  
  74. DialogBox Methods.
  75. ==================
  76.  
  77. Declaration
  78.   constructor Init(NumTextLines, TotalTextChars,
  79.                    NumChoices, TotalChoiceChars: word);
  80. Purpose
  81.   Initialize internal data fields and allocate MStringArrays for storing
  82.   lines of message text and choices.
  83. Description
  84.   NumTextLines is the maximum number of lines of text that you will want
  85.   displayed as a message in the DialogBox.
  86.            TotalTextChars = NumTextLines * AveLengthOfEachLine
  87.   NumChoices is the number of radio buttons that you want. Each radio button
  88.   displays one word from the ChoiceString.
  89.            TotalChoiceChars = NumChoices * (AveLenghtOfEachChoice + 4)
  90.   Since DialogBox uses a descendant of StringArrays for storing the lines of
  91.   message Text to be displayed and the Choices, it is good practice to
  92.   allocate your best estimate of the memory storage requirements through Init.
  93.   However the StringArrays can reallocate if there is enough memory.
  94.   Reallocation will fragment memory.
  95.  
  96. Declaration
  97.   destructor Done; virtual;
  98. Purpose
  99.   Deallocate all memory associated with DialogBox.
  100. Description
  101.   This includes memory for EntryScreen, DialogPick, Text and Choice Arrays.
  102.  
  103. Declaration
  104.   procedure Clear;
  105. Purpose
  106.   To set up the DialogBox for a new message and set of Choices.
  107. Description
  108.   This resets the Message and Choice arrays by disposing of them and then
  109.   reallocating at the same size. The EntryScreen is also disposed and all
  110.   DialogBox data fields reinitialized. It is useful in those situations where
  111.   you want to keep a DialogBox initialized and just keep sending new messages
  112.   and choices.  Using this technique limits heap fragmentation.
  113.  
  114. Declaration
  115.   function GetLastError: word;
  116. Purpose
  117.   To return the last error recorded by DialogBox.
  118. Description
  119.   Returns the error code and resets dlLastError to 0.
  120.  
  121. Declaration
  122.   procedure Process;
  123. Purpose
  124.   To activate the DialogBox in preparation for obtaining user input.
  125. Description
  126.   Process is a little different from other process methods in OPRO. It calls
  127.   the method CreateBox described below to create the pick list (dlPick^) and
  128.   the EntryScreen (dlEntry^); add the text fields, the string entry field (if
  129.   there is one) and the window field (dlPick^). It then calls dlEntry^.Process
  130.   and waits for an exit selection. Process uses the standard OPRO
  131.   EntryCommands and PickCommands sets. If UseMouse is defined, as it is in
  132.   ULDEFINE.INC, and a mouse is installed, the mouse is enabled. After an exit
  133.   selection has been made Process also erases the DialogBox. If SetTimeOut has
  134.   been used to set a delay time before the box is automatically erased,
  135.   Process first calls Draw.
  136.  
  137. Declaration
  138.   procedure AddMessageString(Msg: string);
  139. Purpose
  140.   To add message strings which will be displayed as TextFields in the entry
  141.   screen to be created.
  142. Description
  143.   You can add as many message strings as you want, but keep in mind that only
  144.   those that will display on a full screen will be displayed and the lines
  145.   will be truncated to fit in a full screen window with a border. The entry
  146.   screen window is sized automatically as described under CreateBox. The
  147.   maximum number of text lines that can be displayed is
  148.   (ScreenHeight-5-NumberOfStringFieldLines). You do not have to add a message
  149.   string if you just want the radio buttons. If you stay within the memory
  150.   allocation specified in Init, then this is not likely to fail. Otherwise you
  151.   should check GetLastError after adding.
  152.  
  153. Declaration
  154.   procedure AddChoiceString(Choice: string);
  155. Purpose
  156.   To add exit Choices for the DialogBox.
  157. Description
  158.   Each word in the Choice string is displayed in a radio button box as an exit
  159.   selection. The center row of the radio buttons is a single-choice,
  160.   horizontal pick list. It is an error (epFatal+ecNoChoice) not to add a
  161.   Choice string and the string may not be blank. If you stay within the memory
  162.   allocation requirements specified in Init, this is not likely to fail.
  163.   Otherwise you should check GetLastError after adding.
  164. Example
  165.   AddChoiceString('Sometimes Always Never_On_Sunday');
  166.  
  167.   This would result in the following radio buttons:
  168.           ┌─────────────────┐┌─────────────────┐┌─────────────────┐
  169.           │ Sometimes       ││ Always          ││ Never_On_Sunday │
  170.           └─────────────────┘└─────────────────┘└─────────────────┘
  171.           Choice: 1                  2                  3
  172.  
  173. Declaration
  174.   procedure AddStringEntryField(Prompt: string; pRow, pCol: word;
  175.                                 Picture: string; fRow, fCol: word;
  176.                                 fWidth: byte; HelpIndex: word;
  177.                                 EditSt: string);
  178. Purpose
  179.   To add a string entry field to the DialogBox.
  180. Description
  181.   The use of this method is exactly the same as AddStringField in OPRO. The
  182.   positioning of the field is adjusted in CreateBox as necessary to center the
  183.   field just above the radio buttons. pCol and fCol are adjusted to center the
  184.   entry field inside the box; only their difference is significant. pRow and
  185.   fRow are only used to determine whether the prompt and the field are on the
  186.   same line or if not, which comes first. So the difference between pRow and
  187.   fRow is the only thing that is significant.
  188.  
  189. Declaration
  190.   procedure AddHeader(S: string; Posn: HeaderPosType);
  191. Purpose
  192.   To add a header on the frame of the DialogBox.
  193. Description
  194.   Works just like the similar method in OPRO on the dlEntry^. It can fail
  195.   because of insufficient memory.
  196.  
  197. Declaration
  198.   function GetLastChoice: word;
  199. Purpose
  200.   Returns the number of the Choice that is selected.
  201. Description
  202.   The exit Choices are numbered beginning with 1 in the sequence that they
  203.   appear in the Choice string in AddChoiceString. This should be called after
  204.   Process to get the exit selection.
  205.  
  206. Declaration
  207.   function GetEditedString: string;
  208. Purpose
  209.   Returns the edited string if AddStringEntryField has been used.
  210. Description
  211.   If no entry field has been added, it will always return a blank string.
  212.  
  213. Declaration
  214.   procedure SetTimeOut(Delay: word);
  215. Purpose
  216.   Used to set a time out period (in milliseconds) for DialogBox.
  217. Description
  218.   Sometimes it is useful to display a temporary message that is on the screen
  219.   for a fixed length of time (Delay). If the user presses a key, the timeout
  220.   feature is overridden and the DialogBox reverts to normal key and mouse
  221.   operation. If the DialogBox exits because of timeout, the GetLastChoice will
  222.   return a value of scTimeOut (presently = 99).
  223. Example
  224.           if not MyDialog.Init(1,78,2,20) then Exit;
  225.           with MyDialog do
  226.           begin
  227.             AddMessageString('Test of timeout feature.');
  228.             AddChoiceString('Ok Cancel');
  229.             SetTimeOut(10000);
  230.             Process;
  231.             Code := GetLastChoice;
  232.             Done;
  233.           end;
  234.  
  235.   If a key is not pressed within 10 seconds, Code = scTimeOut.
  236.   If {Enter} is pressed, MyDialog is erased and Code = 1.
  237.   If any other key is pressed, MyDialog reverts to normal operation.
  238.  
  239. Declaration
  240.   function CreateBox: boolean; virtual
  241. Purpose
  242.   Initializes entry screen and pick list and adds fields.
  243. Description
  244.   Normally CreateBox is called automatically by Process; however you may call
  245.   it separately if you want to use non-default features. If CreateBox is
  246.   called prior to Process, then it will not be called in Process. CreateBox
  247.   sizes the entry screen window based on the messages, choices and entry field
  248.   that are added. The window is centered on the screen. The radio buttons are
  249.   in the bottom three rows of the window. If an entry field is added, it is
  250.   centered just above the radio buttons. If all goes well, it returns true.
  251.   When CreateBox exits, all objects are initialized and ready for a call to
  252.   Process or Draw.
  253.  
  254. Comments or suggestions are welcome.
  255.  
  256.