home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / tot5.zip / DEMIO23.PAS < prev    next >
Pascal/Delphi Source File  |  1991-02-11  |  4KB  |  145 lines

  1. program DemoIOTwentyThree;
  2. {demIO23 - DAMN that TAB key!}
  3.  
  4. {This example illustrates how you could use a character hook to
  5.  provide cursor jumping between fields - rather then pressing the
  6.  TAB key.}
  7.  
  8. Uses DOS, CRT,
  9.      totFAST, totREAL, totINPUT, totIO1, totIO2, totIO3, 
  10.      totSTR, totDATE, totMSG;
  11.  
  12. VAR
  13.    Controlkeys: ControlKeysIOOBJ;
  14.    UpKey,DownKey,LeftKey,RightKey,EnterKey: HotkeyIOOBJ;
  15.    Field1,
  16.    Field2,
  17.    Field3,
  18.    Field4,
  19.    Field5,
  20.    Field6,
  21.    Field7,
  22.    Field8,
  23.    Field9: StringIOOBJ;
  24.    Manager: FormOBJ;
  25.    Result: tAction;
  26.  
  27. {$F+}
  28. function EnterFieldTrap(var NextID:word; PrevID:word):tAction;
  29. {Intercepts field changes and checks key that was pressed. If necessary
  30.  the Toolkit is redirected to a different fielf}
  31. var MoveKey: word;
  32.  
  33.     procedure GotoField(U,D,L,R:word);
  34.     {}
  35.     begin
  36.        case Movekey of
  37.        328: NextID := U;
  38.        336: NextID := D;
  39.        371: NextID := L;
  40.        else NextID := R;
  41.        end; {case}
  42.     end;
  43. begin
  44.    MoveKey := Key.Lastkey;
  45.    if (MoveKey = 328) 
  46.    or (MoveKey = 336)  
  47.    or (MoveKey = 371)
  48.    or (MoveKey = 372)
  49.    or (MoveKey = 13) then
  50.       case PrevID of
  51.       1: GotoField(9,4,9,2);     {up,down,left,right}
  52.       2: GotoField(7,5,1,3);
  53.       3: GotoField(5,6,2,4);
  54.       4: GotoField(1,7,3,5);
  55.       5: GotoField(2,3,4,6);
  56.       6: GotoField(3,8,5,7);
  57.       7: GotoField(4,2,6,8);
  58.       8: GotoField(6,9,7,9);
  59.       9: GotoField(8,1,8,1);
  60.       end;
  61.    EnterFieldTrap := none; 
  62. end; {EnterFieldTrap}
  63. {$F-}
  64.  
  65. procedure InitVars;
  66. {}
  67. begin
  68.    UpKey.Init(328,PrevField);
  69.    DownKey.Init(336,NextField);
  70.    LeftKey.Init(371,PrevField);
  71.    RightKey.Init(372,NextField);
  72.    EnterKey.Init(13,NextField);
  73.    Field1.Init(15,5,10);
  74.    Field1.SetLabel('Field 1');
  75.    Field1.SetID(1);
  76.    Field2.Init(40,5,10);
  77.    Field2.SetLabel('Field 2');
  78.    Field2.SetID(2);
  79.    Field3.Init(65,5,10);
  80.    Field3.SetLabel('Field 3');
  81.    Field3.SetID(3);
  82.    Field4.Init(15,8,10);
  83.    Field4.SetLabel('Field 4');
  84.    Field4.SetID(4);
  85.    Field5.Init(40,8,10);
  86.    Field5.SetLabel('Field 5');
  87.    Field5.SetID(5);
  88.    Field6.Init(65,8,10);
  89.    Field6.SetLabel('Field 6');
  90.    Field6.SetID(6);
  91.    Field7.Init(15,11,10);
  92.    Field7.SetLabel('Field 7');
  93.    Field7.SetID(7);
  94.    Field8.Init(65,11,10);
  95.    Field8.SetLabel('Field 8');
  96.    Field8.SetID(8);
  97.    Field9.Init(15,14,60);
  98.    Field9.SetLabel('Field 9');
  99.    Field9.SetID(9);
  100.    Controlkeys.Init;
  101.    with Manager do
  102.    begin
  103.       Init;
  104.       AddItem(Controlkeys);
  105.       AddItem(UpKey);
  106.       AddItem(DownKey);
  107.       AddItem(LeftKey);
  108.       AddItem(RightKey);
  109.       AddItem(EnterKey);
  110.       AddItem(Field1);
  111.       AddItem(Field2);
  112.       AddItem(Field3);
  113.       AddItem(Field4);
  114.       AddItem(Field5);
  115.       AddItem(Field6);
  116.       AddItem(Field7);
  117.       AddItem(Field8);
  118.       AddItem(Field9);
  119.    end;
  120. end; {InitVars}
  121.  
  122. procedure SetUpScreen;
  123. {}
  124. begin
  125.    with Screen do
  126.    begin
  127.       {use the color settings used in the IO form}
  128.       TitledBox(1,1,80,25,
  129.                 IOTOT^.LabelCol(3),
  130.                 IOTOT^.LabelCol(4),
  131.                 IOTOT^.LabelCol(3),
  132.                 1,' TechnoJock''s Hate-that-TAB Demo ');
  133.       WriteCenter(24,79,'To change fields press:      Ctrl'+chr(027)
  134.                         +'  Ctrl'+chr(026)
  135.                         +'  Enter, or the dreaded TAB');
  136.    end;
  137. end; {SetUpScreen}
  138.  
  139. begin
  140.    InitVars;
  141.    SetUpScreen;
  142.    Manager.SetEnterHook(EnterFieldTrap);
  143.    Result := Manager.Go;
  144.    Clrscr;
  145. end.