home *** CD-ROM | disk | FTP | other *** search
- {$R-,S-}
-
- program Test2;
- {-Demonstrate text stream modification inside BINED event handler}
-
- uses
- Crt, {Just for convenience of demo}
- BinEd,
- BinInt; {Makes BinEd internals available to event handlers}
-
- const
- ExitCommands : Char = #0; {No special exit characters}
-
- var
- EdData : EdCB; {Editor control block}
- EdInt : EdIntRec; {Internals record}
-
- procedure Abort(Msg : string);
- begin
- WriteLn(Msg);
- Halt(1);
- end;
-
- {$F+}
- procedure EventHandler(EventNo, KbdFlagInfo : Word);
- {-Event handler reports on internals}
- begin
- if EditOptions(EdInt) and EdOptInsert = EdOptInsert then
- {Editor in insert mode}
- if LinePos(EdInt) <= LineLen(EdInt) then
- {Cursor within current line}
- if CurrChar(EdInt) = ' ' then begin
- {Cursor over a space}
- ClearKbd(EdInt);
- StuffKey(Ord(^T)); {Delete white space to next word}
- StuffKey(Ord(^M)); {Enter}
- end;
- end;
- {$F-}
-
- begin
- if ParamCount = 0 then
- Abort('Usage: TEST2 filename.ext');
-
- {Initialize binary editor for a partial screen window}
- if InitBinaryEditor(EdData, MaxFileSize, 1, 1, 80, 19,
- True, EdOptInsert, '', ExitCommands,
- @EventHandler) <> 0 then
- Abort('Unable to load binary editor.');
-
- {Store internals for event handler}
- FindInternals(EdData, EdInt);
-
- {Read file to edit}
- if ReadFileBinaryEditor(EdData, ParamStr(1)) > 1 then
- Abort('Unable to read '+ParamStr(1));
-
- ClrScr;
-
- {Reset for this file}
- ResetBinaryEditor(EdData);
-
- {Edit it, no save supported}
- if UseBinaryEditor(EdData, '') = -1 then
- ;
-
- GoToXy(1, 25);
- end.