home *** CD-ROM | disk | FTP | other *** search
- Program Demo2;
- {===========================================================================}
- { This program demonstrates how to use *.HLP help files in conjunction
- { with Turbo Pascal 4.0 programs, and how to make use of user-specified
- { "hot keys" and cursor-selected user functions.
- {
- { First use The Helper to compile DEMO2.HLS (supplied with The Helper), to
- { create the help file DEMO2.HLP. Then run this program with Turbo Pascal 4
- { or higher. See how the user functions work. Then try writing your own user
- { functions and help files.
- {
- {-------- User functions defined in this program:
- { DEMO2.HLP contains 2 cursor options which cause a temporary exit to the
- { controlling program (this program) to execute user-defined procedures.
- { In addition, 4 "hot-key" functions are defined in this program, to cause
- { immediate temporary exit to this program. The cursor and hot-key options
- { defined here are:
- { Cursor option 1 : Clear screen and write random numbers
- { Cursor option 2 : Enter a filename and see if it exists
- { Hot-key1 A : Type the letter "A" to sound the bell
- { Hot-key2 C : Type "C" to toggle the category number display
- { Hot-key3 R : Type "R" to redraw the screen (for animated screens)
- { Hot-key4 F2 : No action - The F2=Print function has been suppressed
- {
- { These user-defined functions are incorporated into the procedure Get_Help,
- { so the rest of the program simply needs the statement "Get_Help(Categ);"
- { wherever and whenever it needs to access the help file (once the Help
- { filename has been specified). "Categ" is the requested category of Help,
- { though you can use "Get_Help(0);" to enter Help at the category last used.
- {===========================================================================}
-
- {$M $4000,0,$4000} {Set max heap size. This is only required if the *.hlp }
- {help files you use make use of the DOS shell facility.}
- {The stack and heap values should be at least $4000. }
-
- uses crt, help;
-
- Var
- HelpFileName : String; {The file name of the compiled help file to use}
- Ch1,Ch2 : Char; {Temporary character variables}
-
- Procedure Write_Junk;
- {-----------------------------------------------------------------------}
- { Clear screen and write some random numbers until a key is pressed
- {-----------------------------------------------------------------------}
- Var
- i,j : Byte;
- x : Real;
- Ch : Char;
- Begin
- Window(1,1,80,25); TextAttr:=7; ClrScr;
- Repeat
- i:=Random(60); j:=Random(25); x:=1000*Random;
- GotoXY(i,j); Write(x); Delay(10);
- Until Keypressed;
- Ch:=Readkey; If Ch=#0 then Ch:=Readkey;
- End;
-
- Procedure Check_Filename(Filename : String);
- {-----------------------------------------------------------------------}
- { Check if a file exists, and print a message
- {-----------------------------------------------------------------------}
- Var
- AnyFile : File;
- i : Byte;
- Begin
- {$I-} If Filename<>'' then Assign(AnyFile,Filename);
- Reset(AnyFile); i:=IOresult; {$I+}
- Window(1,1,80,25); TextAttr:=7; GotoXY(1,24);
- If i=0 then Write('File ',Filename,' exists.')
- Else Write('File ',Filename,' does not exist.');
- Write(' Press Enter to return...');
- Readln;
- End;
-
- Procedure Get_Help(Categ : Byte);
- {----------------------------------------------------------------------}
- { Use The Helper, after checking that it has been correctly initialised}
- {----------------------------------------------------------------------}
- Var
- Ch1,Ch2 : Char;
- Fname : String;
- Begin
- SaveHelpBG; {Save background before opening a help screen}
- If not HelpInitialised then Initialise_Help(HelpFileName);
- If HelpInitialised then begin {Use Help, check for exits via hot-keys}
- {and user-defined cursor functions }
- Repeat
- Use_Help(Categ); {Use Help at this category (0=no change)}
- Categ:=HelpCat; {Update Categ, in case the user changed categories}
- Ch1:=Upcase(HelpExitStr[1]);
- {HelpExitStr contains the ASCII value of the hot-key used to exit}
- {Help, or the cursor value if exit was by a cursor option: }
- {eg. "A"-->#65, F10-->#0#68, cursor-->#255,#n }
-
- Case Ch1 of
- 'A' : Write(^G); {sound bell}
- 'C' : HelpShowCat:=not HelpShowCat; {toggle category number display}
- 'R' : Begin End; {no action, redraw screen}
- #255 : Begin {user-defined cursor functions}
- Ch2:=HelpExitStr[2];
- If Ch2=#1 then Write_Junk
- {Write numbers - demo2.hls contains ^A(255,1) .... ^A, so}
- {HelpExitStr=#255#1 when this cursor option is selected }
-
- Else If Ch2=#160 then begin
- {demo2.hls contains ^A(255,160) -------------- ^A, so }
- {HelpExitStr=#255#160 when this cursor option is selected}
- Window(1,1,80,25); TextAttr:=7; GotoXY(1,24);
- Write('Enter any filename: ');
- Readln(Fname);
- Check_Filename(Fname);
- End;
- End;
- End;
- Until Ch1=#27; {Exit when Esc is pressed}
- End;
- RestoreHelpBG; {Restore the original background when leaving Help}
- End;
-
- BEGIN
- {-------Clear screen, and define the help file name}
- ClrScr;
- HelpFileName:='demo2.hlp';
-
- {-------Define the hot-keys which will cause an exit from Help}
- HelpExitChars:='aAcCrR'; {Normal (text) hot-keys = a, A, c, C, r, R }
- HelpExitFuncChars:=#60; {Extended (function keys) hot-keys #60 = F2}
- { Note that the preceeding #0 for function}
- { keys is not required. If F4, F5 and F6 }
- { were required as hot-keys, set }
- { HelpExitFuncChars:=#62#63#64; }
- { Consult Turbo Pascal manual for values }
- { for Ctrl, Function and Alt keys. }
-
- {-------Define the heading for the Help window (optional, "Help" by default)}
- HelpText:='DEMO2';
-
- {-------Write some stuff on the screen, showing some options}
- ClrScr; Writeln;
- Writeln('DEMO2.pas - for use with help file DEMO2.hlp');
- Writeln('-----------------------------------------------');
- Writeln;
- Writeln('Enter F1 for Help at same position as last time');
- Writeln(' F2 for direct access to Help contents');
- Writeln(' F3 for direct access to Help with Help');
- Writeln(' F4 for direct access to DOS functions');
- Writeln(' F5 for direct access to user-defined cursor options');
- Writeln(' F6 for direct access to animation demonstration');
- Writeln(' Esc to quit'); Writeln;
- Write(' ---->');
-
- {-------Demonstrate context-sensitive access to the help file by selecting }
- { from the options.}
- Repeat
- GotoXY(7,13);
- Ch1:=Upcase(Readkey);
- If Ch1=#0 then begin {extended character typed}
- Ch2:=Readkey;
- Case Ch2 of
- #59 : Get_Help(0); {F1 = Help, at last category accessed}
- #60 : Get_Help(1); {F2 = Goto Help contents}
- #61 : Get_Help(2); {F3 = Get Help at category 2 (Help with Help)}
- #62 : Get_Help(7); {F4 = Category 7 - DOS functions}
- #63 : Get_Help(8); {F5 = Category 8 - user functions}
- #64 : Get_Help(9); {F6 = Category 9 - animation demo}
- End;
- End;
- Until Ch1=#27; {Esc=Quit}
-
- {-------Clear screen and end}
- ClrScr;
- END.