home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1990 / 09 / entsming.asc < prev    next >
Text File  |  1990-07-25  |  5KB  |  176 lines

  1. _INSIDE OBJECT PROFESSIONAL_
  2. by Gary Entsminger
  3.  
  4.  
  5. [LISTING ONE]
  6.  
  7. program Edit;
  8. uses OpCrt, OpRoot, OpCmd, OpFrame, OpWindow, OpMemo, OpEditor;
  9. var
  10.   TE : TextEditor;
  11.   FSize : LongInt;
  12.   ExitCommand : Word;
  13.   AllDone : Boolean;
  14. begin
  15.   if not TE.InitCustom(2, 4, 79, 24,           { Window coordinates }
  16.                 DefaultColorSet,               { ColorSet }
  17.                 DefWindowOptions or wBordered, { Win options }
  18.                 65521)                         { Buffer size }
  19.   then
  20.   begin
  21.     WriteLn('Failed to init TextEditor. Status = ', InitStatus);
  22.     Halt;
  23.   end;
  24.   { use built-in status and error handlers provided by OPMEMO }
  25.   TE.SetStatusProc(MemoStatus);
  26.   TE.SetErrorProc(MemoError);
  27.   { Create and Read a text file }
  28.   TE.ReadFile('AnyFile', FSize);
  29.   AllDone := False;
  30.   repeat
  31.     TE.Process;
  32.     ExitCommand := TE.GetLastCommand;
  33.     case ExitCommand of
  34.       ccSaveExit,           { Save and exit -- file already saved }
  35.       ccAbandonFile,        { Abandon file }
  36.       ccError :             { Fatal error }
  37.         AllDone := True;
  38.       {...user exit commands..}
  39.     end;
  40.   until AllDone;
  41.   TE.Erase;
  42.   TE.Done;
  43.   ClrScr;
  44. end.
  45.  
  46.  
  47. [LISTING TWO]
  48.  
  49. program HelloWorld;
  50. Uses HWMain, OpSwap;
  51. begin
  52.   HelloWorldMain;
  53. end;
  54.  
  55. unit HWMain;
  56. interface
  57.  
  58. uses
  59.   OpInLine, OpSwap1;
  60.  
  61. procedure HelloWorldMain;
  62.  
  63. implementation
  64.  
  65. const
  66.   HotKey = $080F { code for ALT-TAB }
  67.   Swap1 = 'Hello1.SWP';
  68.   Swap2 = 'Hello2.SWP';
  69.  
  70.   {$F+}
  71.   procedure PopUpEntryPoint;
  72.   begin
  73.     Writeln('Hello World');
  74.   end;
  75.   {$F-}
  76.  
  77.   procedure HelloWorldMain;
  78.   begin
  79.     SetSwapMsgOn( not WillSwapUseEMS(ParagraphsToKeep) );
  80.     { define the popup }
  81.     if DefinePop(HotKey, PopUpEntryPoint, Ptr($SSeg,SPtr)) then
  82.     begin
  83.       Writeln('PopUp loaded, press <ALT><TAB> to activate.');
  84.       { Make PopUp routines active. }
  85.       PopUpsOn;
  86.       { Try to go resident. }
  87.       StayResSwap(ParagraphsToKeep, 0, Swap1, Swap2, True);
  88.     end;
  89.  
  90.     { If we get here, report failure. }
  91.     Writeln('Unable to go resident. ');
  92.   end;
  93.  
  94. end.
  95.  
  96.  
  97.  
  98. [LISTING THREE]
  99.  
  100. program CommandWindowExample;  {EXCMDWIN.PAS}
  101. uses
  102.   OpCrt, OpRoot, OpCmd, OpFrame, OpWindow;
  103. const
  104.   {Define a trivial KeySet of a few cursor commands}
  105.   KeyMax  = 18;
  106.   KeySet  : array[0..KeyMax] of Byte = (
  107.   {length keys         command type   key sequence}
  108.   3,      $00, $48,    ccUp,          {Up}
  109.   3,      $00, $50,    ccDown,        {Down}
  110.   3,      $00, $4B,    ccLeft,        {Left}
  111.   3,      $00, $4D,    ccRight,       {Right}
  112.   2,      $1B,         ccQuit);       {Esc}
  113. type
  114.   SampleWindow =
  115.     object(CommandWindow)
  116.       procedure Process; virtual;
  117.     end;
  118. var
  119.   Commands : CommandProcessor;
  120.   CmdWin : SampleWindow;
  121.   Finished : Boolean;
  122.   procedure SampleWindow.Process;
  123.   begin
  124.     repeat
  125.       {Get a command}
  126.       GetNextCommand;
  127.       case GetLastCommand of
  128.         ccUp :    WriteLn('ccUp');
  129.         ccDown :  WriteLn('ccDown');
  130.         ccLeft :  WriteLn('ccLeft');
  131.         ccRight : WriteLn('ccRight');
  132.         ccQuit :  WriteLn('ccQuit');
  133.         ccChar :  WriteLn('ccChar: ', Char(Lo(GetLastKey)));
  134.         else      WriteLn('ccNone');
  135.       end;
  136.     until (GetLastCommand = ccQuit) or (GetLastCommand = ccError);
  137.   end;
  138. begin
  139.   {Make a small CommandProcessor}
  140.   Commands.Init(@KeySet, KeyMax);
  141.   {Make a bordered CommandWindow}
  142.   if not CmdWin.InitCustom(30, 5, 50, 15,       {Window coordinates}
  143.                 DefaultColorSet,                {Color set}
  144.                 wBordered+wClear+wSaveContents, {Window options}
  145.                 Commands,                       {Command processor}
  146.                 ucNone)                         {Unit code}
  147.   then begin
  148.     WriteLn('Failed to init CommandWindow. Status = ', InitStatus);
  149.     Halt;
  150.   end;
  151.   {Add headers and draw window}
  152.   CmdWin.wFrame.AddHeader(' Command window ', heTC);
  153.   CmdWin.wFrame.AddHeader(' <Esc> to Quit ', heBC);
  154.   CmdWin.Draw;
  155.   {Get and process commands}
  156.   Finished := False;
  157.   repeat
  158.     CmdWin.Process;
  159.     case CmdWin.GetLastCommand of
  160.       ccQuit : Finished := True;                         {Quit}
  161.       ccError : begin                                    {Error}
  162.                   WriteLn('Error: ', CmdWin.GetLastError);
  163.                   Finished := True;
  164.                 end;
  165.       ccUser0..ccUser55 : WriteLn('user command'); {Handle exit command}
  166.     end;
  167.   until Finished;
  168.   {Clean up}
  169.   CmdWin.Done;
  170.   Commands.Done;
  171. end.
  172.  
  173.  
  174.  
  175.  
  176.