home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / BININT.ZIP / TEST2.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1988-10-22  |  1.8 KB  |  69 lines

  1. {$R-,S-}
  2.  
  3. program Test2;
  4.   {-Demonstrate text stream modification inside BINED event handler}
  5.  
  6. uses
  7.   Crt,                            {Just for convenience of demo}
  8.   BinEd,
  9.   BinInt;                         {Makes BinEd internals available to event handlers}
  10.  
  11. const
  12.   ExitCommands : Char = #0;       {No special exit characters}
  13.  
  14. var
  15.   EdData : EdCB;                  {Editor control block}
  16.   EdInt : EdIntRec;               {Internals record}
  17.  
  18.   procedure Abort(Msg : string);
  19.   begin
  20.     WriteLn(Msg);
  21.     Halt(1);
  22.   end;
  23.  
  24.   {$F+}
  25.   procedure EventHandler(EventNo, KbdFlagInfo : Word);
  26.     {-Event handler reports on internals}
  27.   begin
  28.     if EditOptions(EdInt) and EdOptInsert = EdOptInsert then
  29.       {Editor in insert mode}
  30.       if LinePos(EdInt) <= LineLen(EdInt) then
  31.         {Cursor within current line}
  32.         if CurrChar(EdInt) = ' ' then begin
  33.           {Cursor over a space}
  34.           ClearKbd(EdInt);
  35.           StuffKey(Ord(^T)); {Delete white space to next word}
  36.           StuffKey(Ord(^M)); {Enter}
  37.         end;
  38.   end;
  39.   {$F-}
  40.  
  41. begin
  42.   if ParamCount = 0 then
  43.     Abort('Usage: TEST2 filename.ext');
  44.  
  45.   {Initialize binary editor for a partial screen window}
  46.   if InitBinaryEditor(EdData, MaxFileSize, 1, 1, 80, 19,
  47.                       True, EdOptInsert, '', ExitCommands,
  48.                       @EventHandler) <> 0 then
  49.     Abort('Unable to load binary editor.');
  50.  
  51.   {Store internals for event handler}
  52.   FindInternals(EdData, EdInt);
  53.  
  54.   {Read file to edit}
  55.   if ReadFileBinaryEditor(EdData, ParamStr(1)) > 1 then
  56.     Abort('Unable to read '+ParamStr(1));
  57.  
  58.   ClrScr;
  59.  
  60.   {Reset for this file}
  61.   ResetBinaryEditor(EdData);
  62.  
  63.   {Edit it, no save supported}
  64.   if UseBinaryEditor(EdData, '') = -1 then
  65.     ;
  66.  
  67.   GoToXy(1, 25);
  68. end.
  69.