home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TPHELP.ZIP / TPHELP.DOC < prev    next >
Encoding:
Text File  |  1988-02-07  |  22.3 KB  |  510 lines

  1.                  Help Facility for Turbo Pascal 4.0
  2.                  ----------------------------------
  3.                             Kim Kokkonen
  4.                          TurboPower Software
  5.                              Version 1.0
  6.                                2/7/88
  7.  
  8. Overview
  9. ---------------------------------------------------------------------
  10. If you've ever had to develop a help facility for a Turbo Pascal
  11. application, you know that it takes some effort to write one that is
  12. efficient and easy to use. The help facility here offers a powerful,
  13. easy method to incorporate help screens into Turbo Pascal 4.0 programs.
  14.  
  15. The Help Facility for Turbo Pascal 4.0, herein called TPHELP, consists
  16. of two parts. A Turbo Pascal unit, TPHELP.TPU, will be compiled into a
  17. program that needs to make use of the help facility. A "help file
  18. compiler", MAKEHELP.EXE, will convert a text file containing the desired
  19. help to an indexed binary file for use by TPHELP itself.
  20.  
  21. The binary help file can be linked into the target program, so that no
  22. additional files are required by the end user of the application.
  23. Alternately, for large applications or large help files, the file may be
  24. left separate and paged automatically into memory by TPHELP.
  25.  
  26. The help system supports up to 16000 help topics in one file, each of
  27. which may have up to 20 pages of help information. Help is displayed in
  28. a pop-up window through which the user may browse. Various formatting
  29. controls allow help to appear in up to four different video attributes.
  30. The help compiler word-wraps and paginates the original help text, under
  31. the control of directives that you insert.
  32.  
  33. Within the application program, help may be selected by topic name, by
  34. index number, or by letting the user choose a topic from a pick window.
  35. You may also activate a "context-sensitive help system", which pops help
  36. up automatically whenever the user presses a specified key.
  37.  
  38. You must have the commercial product Turbo Professional 4.0 in order to
  39. compile and use TPHELP. See the Advertisement section below for more
  40. information on obtaining Turbo Professional 4.0. This help facility
  41. includes complete source code for TPHELP and MAKEHELP. To enable certain
  42. features of TPHELP, you must also have the Turbo Professional "bonus"
  43. unit TPPICK. You can obtain the TPPICK source code by downloading
  44. TPPICK.ARC from Compuserve (GO BPROGA, DL2).
  45.  
  46.  
  47. Initializing a Help System
  48. ---------------------------------------------------------------------
  49. TPHELP exports several data types and routines so that a client
  50. program can easily integrate a help system. The main data type is:
  51.  
  52. type
  53.   HelpPtr = ^HelpDesc;       {The user hook to the help system}
  54.  
  55. A variable of this type points to a data structure that lets TPHELP
  56. manage the help system. The client program needs only to declare a
  57. variable of this type (which uses 4 bytes of space in whatever segment
  58. it's declared) and initialize it as described below, in order to
  59. access the help system.
  60.  
  61. TPHELP offers the following two functions to initialize a help system.
  62. One of these must be called prior to displaying help.
  63.  
  64. function OpenHelpFile(HelpFileName : string;
  65.                       XLow, YLow, YHigh : Byte;
  66.                       var Help : HelpPtr) : Word;
  67.   {-Find and open help file, returning 0 or error code, and
  68.     an initialized help descriptor if successful}
  69.  
  70. function OpenHelpMem(HPtr : Pointer;
  71.                      XLow, YLow, YHigh : Byte;
  72.                      var Help : HelpPtr) : Word;
  73.   {-Initialize help descriptor for a help structure bound into code}
  74.  
  75. procedure SetHelpPos(Help : HelpPtr; XLow, YLow, YHigh : Byte);
  76.   {-Change the position and height of a help window}
  77.  
  78. OpenHelpFile and OpenHelpMem offer complementary methods of initializing
  79. a help system. OpenHelpFile looks for a binary help file on disk. It
  80. searches first in the current directory, then in the directory of the
  81. main program's EXE file (if DOS 3.x is in use), and finally on the DOS
  82. PATH.
  83.  
  84. OpenHelpMem initializes the help system based on binary help
  85. information linked into the program. Its first parameter is a pointer
  86. to the help structure. More on using this option later.
  87.  
  88. Both OpenHelpMem and OpenHelpFile take XLow, YLow parameters. These
  89. specify the screen position of the upper left corner of the help window.
  90. YHigh specifies the lower (row) boundary of the help window. The width
  91. of the help window is defined within the help file itself. Since it used
  92. to word wrap the help text, the width of a help window may not be
  93. changed within an application.
  94.  
  95. Since the pop-up help window will typically appear at the same screen
  96. location throughout an application, by specifying the position once when
  97. the help system is initialized, you can avoid respecifying it every time
  98. help is called.
  99.  
  100. If you need to move the help window or change its height from time to
  101. time, you can do so by calling the SetHelpPos routine interfaced by
  102. TPHELP. Do not call SetHelpPos until the Help variable has been
  103. initialized by a call to OpenHelpMem or OpenHelpFile.
  104.  
  105. The colors used for pop-up help are obtained from typed constants
  106. HelpColorAttr and HelpMonocAttr defined within TpHelp. You can accept
  107. the default values of these typed constants, or modify them prior to
  108. calling OpenHelpMem or OpenHelpFile. Each typed constant is an array of
  109. six bytes, each one specifying the video attribute of one part of the
  110. help display. The attribute values are bytes that combine both the
  111. foreground and background colors, just like attributes passed to
  112. FastWrite. The attributes are specified in the following order:
  113.  
  114.   FrameAttr TextAttr HeaderAttr SpAttr1 SpAttr2 SpAttr3
  115.  
  116. FrameAttr is used to draw the frame of the pop-up help box. TextAttr is
  117. the default attribute for text drawn within the help window. HeaderAttr
  118. is the attribute for information on the frame, such as the topic title
  119. and help prompts. SpAttr1 through SpAttr3 are alternate attributes that
  120. may be used to highlight the help text. More on activating these
  121. alternate attributes below.
  122.  
  123. The frame type that surrounds the pop-up help window is determined by
  124. the value in TpCrt.FrameChars at the time of the call to OpenHelpMem
  125. or OpenHelpFile.
  126.  
  127. Upon successful completion, OpenHelpMem and OpenHelpFile return an
  128. initialized HelpPtr and a status word of zero. Otherwise, they return
  129. a non-zero error code that corresponds to a Turbo Pascal runtime
  130. error. Errors may occur because the help file isn't found, the file is
  131. not of the appropriate format, or insufficient heap space is
  132. available. (Both routines allocate heap space to hold a header record.
  133. If the help is kept on disk, an additional heap buffer is allocated to
  134. hold the largest help section.)
  135.  
  136.  
  137. Displaying Help
  138. ---------------------------------------------------------------------
  139. TPHELP offers three methods of displaying help. You can call one or
  140. more of them at appropriate places in your program.
  141.  
  142. function ShowHelp(Help : HelpPtr; Item : Word) : Boolean;
  143.   {-Display help screen, returning true if successful}
  144.  
  145. function ShowHelpByName(Help : HelpPtr; Name : string) : Boolean;
  146.   {-Display help screen for topic with pick name Name}
  147.  
  148. function PickHelp(Help : HelpPtr; XLow, YLow, YHigh, PickCols : byte) : word;
  149.   {-Display help pick list, returning Item number, or 0 for none}
  150.  
  151. A bit of background: each help topic is referenced by an Item number
  152. (which ranges from 1 to the maximum topic number) and optionally by a
  153. topic Name. The Item number and Name for each topic are assigned by
  154. you in the original text help file.
  155.  
  156. If no Name is assigned to each item, the only method for displaying
  157. help is the function ShowHelp. Call it by passing the previously
  158. initialized HelpPtr and the Item number. A successful call to ShowHelp
  159. will pop a window onto the screen, allow the user to browse through
  160. the help, and return when the user presses <Esc>. If ShowHelp
  161. succeeds, it will return True, otherwise False. It might return False
  162. if the Help variable isn't initialized, if no help exists for the
  163. specified Item, if a disk error occurs, or if sufficient heap space is
  164. not available to save the screen under the pop-up window.
  165.  
  166. If a Name is assigned to each item, the other two help access methods
  167. become available. ShowHelpByName takes a topic Name as its second
  168. parameter, and displays help for the topic just like ShowHelp.
  169. Matching of the name to the original topic name is case-insensitive.
  170. ShowHelpByName returns false if no matching name is found.
  171.  
  172. PickHelp allows the user to choose from a list of help items, and
  173. returns the selected Item number. The item number may then be passed
  174. to ShowHelp for display. XLow, YLow and YHigh specify the screen
  175. coordinates of the pick window, including its frame. PickCols
  176. specifies how many columns of pick items to display. The value of
  177. XHigh is computed by PickHelp based on the value of PickCols.
  178. PickHelp will return 0 (an invalid item number) if the user presses
  179. <Esc> to exit the pick list, or if an error occurs within PickHelp.
  180. Otherwise it returns a valid item number.
  181.  
  182. See the discussion later about implementing context-sensitive help
  183. systems.
  184.  
  185.  
  186. Using the Help Compiler
  187. ---------------------------------------------------------------------
  188. The text that will eventually be displayed by the help system starts
  189. out as a text file that you must write. You put directives in that
  190. text file to tell the help compiler how to format it. You then run the
  191. help compiler, MAKEHELP, to create a formatted, indexed file that will
  192. be used by the help system.
  193.  
  194. We typically use the extension .TXT to indicate a help text file, and
  195. reserve the extension .HLP for the binary help file produced by
  196. MAKEHELP. The help system does not require this, however.
  197.  
  198. Directives are denoted by an exclamation point that appears as the
  199. first character on a line, immediately followed by the directive name,
  200. followed by various options separated by one or more spaces. Here is a
  201. list of the directives accepted by the help compiler.
  202.  
  203.  
  204.   !WIDTH Width
  205.  
  206.     Specifies the number of columns to be occupied by the help window,
  207.     including the frame. The help will eventually be displayed with one
  208.     blank column separating the text from each edge of the frame. Thus,
  209.     the actual width for text is (Width-4) columns. If no !WIDTH
  210.     directive is specified, MAKEHELP assumes Width=40.
  211.  
  212.     Because MAKEHELP word wraps the text, the width specification for a
  213.     help system is built into the help file. The width cannot be changed
  214.     when the help is later displayed. By contrast, MAKEHELP does not
  215.     automatically paginate the help text, thus allowing help screens
  216.     that can automatically adjust between 25, 43, and 50 line text
  217.     modes.
  218.  
  219.     The !WIDTH directive must appear before the first !TOPIC directive.
  220.  
  221.     Example: !WIDTH 70
  222.  
  223.  
  224.  
  225.   !TOPIC Item [Name]
  226.  
  227.     Each help topic must begin with a !TOPIC directive. Typically,
  228.     help topics will be entered in ascending numerical order, starting
  229.     with number 1. The !TOPIC directive may also specify an optional
  230.     topic name. The name may contain spaces, and it will later appear
  231.     on-screen exactly as entered in the !TOPIC directive. (The topic
  232.     name appears as the title of the help window, and as an entry in
  233.     the help pick list.)
  234.  
  235.     The total space for Names in the help file is limited to 64K
  236.     bytes. Space used for names is equal to the length of the longest
  237.     name plus one times the total number of help topics. When topic
  238.     names are used, this restriction will probably set the limit on
  239.     the maximum number of topics in a help file. MAKEHELP assures that
  240.     the 64K limit is not exceeded.
  241.  
  242.     Lines (even blank ones) immediately following the !TOPIC directive
  243.     start the help text for that topic. The topic continues until
  244.     another !TOPIC directive is found or end of file is reached.
  245.  
  246.     Each help file must have at least one help !TOPIC. The item number
  247.     0 is reserved by the help system to indicate an error, so you
  248.     should never specify !TOPIC 0.
  249.  
  250.     Examples: !TOPIC 1 First Help Section
  251.               !TOPIC 22
  252.  
  253.  
  254.   !LINE
  255.  
  256.     This directive forces MAKEHELP to finish the current line of text,
  257.     inserting a line break. Since MAKEHELP automatically fills and
  258.     word-wraps the text in your original help file, the line breaks
  259.     in the final help screens are not necessarily the same as those in
  260.     the original text file. The !LINE command gives you appropriate
  261.     control when needed. MAKEHELP also inserts a line break whenever it
  262.     encounters a blank line or a line that begins with one or more
  263.     spaces.
  264.  
  265.  
  266.   !PAGE
  267.  
  268.     This directive forces MAKEHELP to finish the current page of text,
  269.     inserting a page break. Normally, TPHELP paginates the help text
  270.     automatically when the help is displayed. For best appearance,
  271.     however, you may wish to force page breaks at selected locations in
  272.     your help file.
  273.  
  274.  
  275. You may enter comments in the text file that will not appear in the
  276. final help. Comments are indicated when a semicolon appears in the
  277. first column of the text file. Example:
  278.  
  279. ;ANY TEXT APPEARING AFTER THE SEMICOLON IS IGNORED.
  280.  
  281. To activate the special text attributes, you insert control characters
  282. directly into your help text. ^A toggles SpAttr1 on and off, ^B
  283. toggles SpAttr2, and ^C toggles SpAttr3. The actual control characters
  284. will not appear in the final help screens. To enter such characters
  285. using the Turbo Pascal editor, first press <CtrlP>, then hold down the
  286. Ctrl key and press the desired character.
  287.  
  288. When the special attributes are used in combination, they are applied
  289. in priority order. SpAttr1 takes priority over SpAttr2, which takes
  290. priority over SpAttr3.
  291.  
  292. SpAttr1 has a special purpose as well. The selected topic in the help
  293. pick menu is displayed in attribute SpAttr1.
  294.  
  295. See DEMOHELP.TXT, supplied here, for a complete example of a help text
  296. file.
  297.  
  298. To run the help compiler, enter the following command from the DOS
  299. prompt:
  300.  
  301.   MAKEHELP HelpTextFile HelpBinaryFile
  302.  
  303. MAKEHELP will read from the text file specified as HelpTextFile and
  304. will create a new binary file HelpBinaryFile. MAKEHELP will overwrite
  305. any existing HelpBinaryFile without warning.
  306.  
  307. MAKEHELP makes two passes through the input text: one to determine the
  308. number of help items and whether any topic names are specified; and a
  309. second to actually format the text and write output.
  310.  
  311. If MAKEHELP finds any errors, it will halt and report the error type
  312. and line number within your help text file.
  313.  
  314. TPHELP comes with a demonstration program, DEMOHELP.PAS, and a
  315. corresponding help file DEMOHELP.TXT. Take a look at these for an
  316. example.
  317.  
  318.  
  319. Binding Help Into a Program
  320. ---------------------------------------------------------------------
  321. TPHELP will directly read the binary file produced by MAKEHELP.
  322. However, if the help file is relatively small (definitely less than
  323. 64K), you may want to link the help file directly into the application
  324. so that no additional files are required at runtime.
  325.  
  326. You can do this with the aid of the BINOBJ.EXE utility that Borland
  327. supplies with Turbo Pascal. BINOBJ converts the binary help file into
  328. a linkable OBJ file that can be bound into your program.
  329.  
  330. Let's use an example to show how this works. Assume you have a help
  331. text file named MYHELP.TXT. The first step would be to run
  332. MAKEHELP.EXE to create the binary help file:
  333.  
  334.   MAKEHELP MYHELP.TXT MYHELP.HLP
  335.  
  336. Then run BINOBJ to create the OBJ file:
  337.  
  338.   BINOBJ MYHELP.HLP MYHELP.OBJ MYHELP
  339.  
  340. The third parameter to BINOBJ specifies the name of the public
  341. identifier by which your program can refer to the contents of the OBJ
  342. file.
  343.  
  344. Now, within your application program, insert the following lines of
  345. source code:
  346.  
  347.   {$L MYHELP.OBJ}
  348.   procedure MyHelp; external;
  349.  
  350. The $L compiler directive tells Turbo to link in MYHELP.OBJ. The fake
  351. procedure MyHelp gives your program a way to refer to the contents of
  352. that OBJ file.
  353.  
  354. Finally, to initialize the help system, make a call to OpenHelpMem as
  355. follows:
  356.  
  357.   Status := OpenHelpMem(@MyHelp, Col, TopRow, BotRow, Help);
  358.   if Status <> 0 then
  359.     {Error, help not available};
  360.  
  361. The notation @MyHelp passes the address of the binary structure to the
  362. help system initialization procedure.
  363.  
  364. From then on, simply refer to the Help variable returned by
  365. OpenHelpMem.
  366.  
  367.  
  368. Context Sensitive Help
  369. ---------------------------------------------------------------------
  370. Context sensitive help means that the user of a program can press a
  371. help key at any time during operation, and the help system will
  372. respond with information appropriate to the user's current actions.
  373.  
  374. TPHELP implements one method of providing context sensitive help, in a
  375. fashion that is quite transparent to your program, by installing an
  376. interrupt handler for the keyboard interrupt. When context sensitive help
  377. has been activated, TPHELP "sits on" interrupt 16h, watching for a
  378. specified help key. When the help key, perhaps <F1>, is detected, TPHELP
  379. pops up the help window, displaying the current help topic. TPHELP can
  380. detect the help key when entered during any ReadLn, ReadKey, or
  381. ReadKeyWord call. When the user finishes looking at help, the interrupt
  382. handler returns to the application as if nothing had happened.
  383.  
  384. It is your program's responsibility to maintain an appropriate value for
  385. the current help topic at all times. TPHELP interfaces a Word variable
  386. named CurrentTopic. Your program must assign the appropriate help topic
  387. number to this variable as execution of the program proceeds. Should you
  388. enter a region of program operation where no help is available, assign
  389. the value 0 to CurrentTopic to temporarily disable context sensitive
  390. help. Otherwise, assign one of your previously defined help topic numbers
  391. to CurrentTopic.
  392.  
  393. TPHELP provides two procedures that your program can call to activate and
  394. deactivate context sensitive help:
  395.  
  396. procedure SetContextHelp(Help : HelpPtr; Key : Word);
  397.   {-Install a keyboard interrupt handler to pop help when Key is pressed}
  398.  
  399. procedure RemoveHelp;
  400.   {-Deinstall context sensitive help}
  401.  
  402. You must call SetContextHelp to activate context sensitive help.
  403. SetContextHelp takes two parameters: Help is a previously initialized
  404. HelpPtr, and Key is the scan word of the help key. For example, the scan
  405. word of the <F1> key is $3B00. Another reasonable choice might be <AltH>,
  406. whose scan word is $2300.
  407.  
  408. To avoid problems with DOS re-entrancy, context sensitive help is
  409. available _only_ when the help file has been converted to an OBJ file and
  410. linked into the program. Thus the Help parameter to SetContextHelp must
  411. have been initialized by a call to OpenHelpMem. SetContextHelp enforces
  412. this requirement, and will not activate context sensitive help otherwise.
  413. (If your program never reads the keyboard using DOS services, this
  414. precaution is unnecessary. For safety's sake, it is always enforced in
  415. TPHELP.)
  416.  
  417. SetContextHelp allocates 2000 bytes of heap space when you call it the
  418. first time. This 2000 bytes is used as an alternate stack -- the
  419. interrupt 16h handler switches to this stack prior to popping up the help
  420. window, just in case it has taken control when little stack space is
  421. available. If SetContextHelp cannot allocate 2000 bytes, it will not
  422. activate the context sensitive help system.
  423.  
  424. You can call RemoveHelp at any time to remove the keyboard interrupt
  425. handler. You probably won't need to though, since RemoveHelp is called
  426. automatically when your program halts.
  427.  
  428. The following skeleton program shows how to use the context sensitive
  429. help system.
  430.  
  431.     ...
  432.     var
  433.       Help : HelpPtr;
  434.       Status : word;
  435.     ...
  436.     {$L MYHELP.OBJ}
  437.     procedure MyHelp; external;
  438.     ...
  439.     begin
  440.       {Initialize help pointer}
  441.       Status := OpenHelpMem(@MyHelp, XLow, YLow, YHigh, Help);
  442.       if Status = 0 then
  443.         {Successful initialization, pop up help with F1 key}
  444.         SetContextHelp(Help, $3B00);
  445.       {Set current topic to appropriate value}
  446.       CurrentTopic := 20;
  447.       ...
  448.       {Change topic}
  449.       CurrentTopic := 3;
  450.       ...
  451.     end.
  452.  
  453. Whenever your program is reading the keyboard via ReadLn or ReadKey and
  454. the user presses <F1>, the help window will pop up to display information
  455. about the current topic.
  456.  
  457.  
  458. Copyright
  459. ---------------------------------------------------------------------
  460. TPHELP and MAKEHELP are copyright (c) 1988 by TurboPower Software, all
  461. rights reserved. The help facilities may be used and distributed freely
  462. by owners of Turbo Professional 4.0.
  463.  
  464.  
  465. Advertisement
  466. ---------------------------------------------------------------------
  467. TurboPower Software is in the business of providing powerful tools for
  468. the Turbo Pascal programmer. Our line of products for Turbo Pascal 3.0
  469. includes the TurboPower Utilities, Turbo Extender, T-DebugPLUS, and
  470. Turbo Optimizer.
  471.  
  472. Our first product for Turbo Pascal 4.0 is Turbo Professional 4.0, a
  473. library of 400 routines to solve the most common programming problems.
  474. Professional 4.0 includes units to save time and effort in the
  475. following ways:
  476.  
  477.   o CRT unit emulation, with many added features: cursor manipulation,
  478.     support for Taskview and Desqview multitaskers, screen save and
  479.     restore, BufLen control, and more.
  480.   o Popup windows, virtual screens, and pulldown menu systems.
  481.   o Easy and reliable ways to make your program memory resident.
  482.   o Interrupt service routine handlers.
  483.   o Keyboard macros.
  484.   o Data entry routines.
  485.   o Extended and Expanded memory access.
  486.   o A complete BCD arithmetic unit, including the transcendental
  487.     functions and the Form routine.
  488.   o Sorting and searching.
  489.   o Extensive string manipulation.
  490.   o Strings longer than 255 characters.
  491.   o Arrays larger than 64K.
  492.   o Runtime error recovery.
  493.  
  494. Turbo Professional 4.0 also comes with a dozen powerful demo programs,
  495. including a memory resident programmer's calculator, time management
  496. system, and keyboard macro utility, as well as a source code generator
  497. for menu systems. With complete source code (over 30,000 lines of it)
  498. and a 450 page manual, Turbo Professional 4.0 is a bargain at $99.
  499.  
  500. Also available is Overlay Manager 4.0, which adds overlays and
  501. chaining back to the Turbo Pascal 4.0 compiler. Just $45.
  502.  
  503. Coming in February '88 is a Turbo 4.0 version of T-DebugPLUS, our
  504. acclaimed symbolic debugger for Turbo Pascal.
  505.  
  506. Following soon thereafter will be Turbo Analyst 4.0, the successor to
  507. our popular TurboPower Utilities.
  508.  
  509. Call TurboPower Software at 408-438-8608 for more information.
  510.