home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / LOOKER.ZIP / LOOKER.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-10-09  |  19.8 KB  |  822 lines

  1. unit looker;
  2.  
  3. interface
  4.  
  5. uses  TPCrt, TPEdit, TPString, TPWindow, TAccess;
  6.  
  7. var
  8.   Fields : string;
  9.  
  10. procedure makeparmstr(Dtype:word; var field; Mask:string);
  11.  
  12. function Look(var KFile :IndexFile;  var DFile : DataFile; var Rcrd;
  13.                        FldStr: string; Depth, X, Y: integer;
  14.                        InKey:string; KeyMask: String): Longint;
  15.  
  16. implementation
  17.  
  18. const
  19.    NumSet : set of char = ['0'..'9'];
  20.    MaskSet  : set of char = ['@','*','#','x','X'];
  21.  
  22.  
  23. var
  24.   MainWAttr, EditWAttr, MainFAttr, EditFAttr,
  25.   MainHAttr, EditHAttr, BarAttr: word;
  26.   MainHeader, EditHeader{, Fields} : string;
  27.  
  28.  
  29. function Expand(InString: string): string;
  30. var i, x, r : integer;
  31.   Temp1, Temp2 : String;
  32.   Error: boolean;
  33.  
  34. begin
  35.    i := 1; Error := false; Temp2 := '';
  36.    while (i <= length(instring)) and (not error) do begin
  37.       Temp1 := '';
  38.       if instring[i] in NumSet then begin
  39.             repeat
  40.                Temp1 := Temp1 + Instring[i];
  41.                inc(i);
  42.             until not(Instring[i] in NumSet);
  43.             val(Temp1, x, r);
  44.             if r > 0 then Error := true;
  45.             if x > 80 then Error:= true;
  46.             if not Error then begin
  47.                FillChar(Temp1, x+1, Instring[i]);
  48.                Temp1[0] := chr(x);
  49.                inc(i);
  50.                Temp2 := Temp2 + Temp1
  51.             end;
  52.          end
  53.       else begin
  54.          Temp2 := Temp2 + Instring[i];
  55.          inc(i);
  56.       end;
  57.    end;
  58.    if Error then
  59.       Expand := 'bad Mask'
  60.    else
  61.       Expand := Temp2
  62. end;
  63.  
  64.  
  65. procedure makeparmstr(Dtype:word; var field; Mask:string);
  66. var
  67.   tempstr:string;
  68. begin
  69.   Mask := Expand(Mask);
  70.   tempstr:=long2str(seg(field));
  71.   fields :=fields+','+tempstr;
  72.   tempstr:=long2str(ofs(Field));
  73.   fields:=fields+','+tempstr;
  74.   tempstr:=long2str(dtype);
  75.   if Mask = '' then Mask := ' ';
  76.   fields:=fields+','+tempstr+','+Mask;
  77. end;
  78.  
  79.  
  80. function Look;
  81.  
  82. const
  83.    EndKey    = $4F {#79};
  84.    PgDnKey   = $51 {#81};
  85.    PgUpKey   = $49 {#73};
  86.    CRKey     = $0D {#13};
  87.    UpKey     = $48 {#72};
  88.    DwnKey    = $50 {#80};
  89.    HomKey    = $47 {#71};
  90.  
  91. type
  92.   ItemPointer = ^Item;
  93.   Item = record
  94.     Segment, Offset, Typ : word;
  95.     Mask : string;
  96.     Next : ItemPointer
  97.   end;
  98.  
  99. var
  100.   List, Spec, FrontNode, RearNode : ItemPointer;
  101.  
  102. var
  103.   T_Key, TmpKy,
  104.   PointKey, SaveKey    : String;
  105.   Line, NewX,
  106.   DatRef, SaveRef      : LongInt;
  107.   KeyWord              : word;
  108.   Segment, Offset      : integer;
  109.   Main,SubWin          : WindowPtr;
  110.   WindowsOn, Complete  : boolean;
  111.   WinWidthStr          : string;
  112.   Width                : word;
  113.   NumNodes             : integer;
  114.   DupKeys              : boolean;
  115.  
  116.   procedure ErrorMem(ErrNbr:integer);
  117.   var
  118.    OpStr : string;
  119.  
  120.   begin
  121.     window(1,1,80,25);
  122.     NormVideo;
  123.     ClrScr;
  124.     FastWrite('Insufficient memory available to continue processing.',10,13,MainWAttr);
  125.     Case ErrNbr of
  126.       1 : OpStr := '  Unable to allocate enough memory to make Main window!!';
  127.       2 : OpStr := '  Unable to allocate enough memory to make Edit window!!';
  128.       3 : OpStr := 'Unable to allocate enough memory to display Main window!!';
  129.       4 : OpStr := 'Unable to allocate enough memory to display Edit window!!';
  130.     end;
  131.     FastWrite(OpStr,11,11,MainWAttr);
  132.     Halt(1);
  133.   end;
  134.  
  135.   procedure Beep;
  136.   begin
  137.     write(^G);
  138.   end;
  139.  
  140. {----- Construct the windows and display them...if false is returned by -----}
  141.  
  142.   procedure DisplayMain;
  143.   begin
  144.     if not MakeWindow(Main,X,Y,X+Width,Y+Depth,True,True,True,
  145.                       MainWAttr,MainFAttr,MainHAttr,MainHeader) then
  146.       ErrorMem(1)
  147.     else
  148.        if not MakeWindow(SubWin,1,23,80,25,True,True,True,
  149.                          EditWAttr,EditFAttr,EditHAttr,EditHeader) then
  150.          ErrorMem(2)
  151.        else
  152.           if not DisplayWindow(SubWin) then
  153.             ErrorMem(3)
  154.           else
  155.              begin
  156.                FastWriteWindow('Use Arrows, PgUp, PgDn, Home, End, or Enter String: ',1,2,MainWAttr);
  157.                if not DisplayWindow(Main) then
  158.                  ErrorMem(4);
  159.              end;
  160.   end;
  161.  
  162.   procedure ClearBox;
  163.   begin
  164.      ClrScr;
  165.   end;
  166.  
  167.  
  168.  
  169. function IVal(NumStr: string) : integer;
  170. var result, TempVal : integer;
  171. begin
  172.    val(NumStr, TempVal, Result);
  173.    if Result > 0 then
  174.       IVal := 0
  175.    else
  176.       IVal := TempVal
  177. end;
  178.  
  179. Procedure DisposeList;
  180. begin
  181.   List := FrontNode;
  182.   while list <> nil do begin
  183.     Dispose(List);
  184.     List := List^.next;
  185.   end;
  186. end;
  187.  
  188. {--- Build a Queue linked list of the FldStr Parameters ---}
  189.  
  190. procedure ParseFldStr;
  191.  
  192. var
  193.   i : integer;
  194.   TempStr : string;
  195.  
  196. {--- extract the individual elements from the
  197.      parameter list (FldStr) ---}
  198.  
  199. procedure BuildTemp;
  200. begin
  201.  TempStr := '';
  202.  if FldStr[i] = ',' then inc(i);
  203.  while (FldStr[i] <> ',') and (i <= length(FldStr))  do begin
  204.     TempStr := TempStr + FldStr[i];
  205.     inc(i);
  206.   end;
  207. end;
  208.  
  209. {--- build the linked list ---}
  210.  
  211. begin
  212.   WinWidthStr := '';
  213.   i := 2;
  214.   NumNodes := 0;
  215.   FrontNode := nil;
  216.   while i < length(FldStr) do begin
  217.     inc(NumNodes);
  218.     new(Spec);
  219.       BuildTemp;
  220.       Spec^.Segment := Ival(TempStr);
  221.       BuildTemp;
  222.       inc(i);
  223.       Spec^.Offset := Ival(TempStr);
  224.       BuildTemp;
  225.       inc(i);
  226.       Spec^.Typ := Ival(TempStr);
  227.       BuildTemp;
  228.       inc(i);
  229.       TempStr := Expand(TempStr);
  230.       Spec^.Mask := TempStr;
  231.       WinWidthStr := WinWidthStr + TempStr;
  232.       Spec^.next := nil;
  233.       if FrontNode = nil then begin
  234.       FrontNode := Spec;
  235.       RearNode := Spec;
  236.     end else begin
  237.       RearNode^.next := Spec;
  238.       RearNode := Spec;
  239.     end;
  240.   end;
  241.   if FldStr = '' then
  242.     Width := Length(KeyMask)+4
  243.   else
  244.     Width := length(WinWidthStr)+Length(KeyMask)+NumNodes*2+4;
  245.   if Width+x > 80 then Width := 80-x;
  246. end;
  247.  
  248.   {-----Construct the string of the data fields -----}
  249.  
  250. function ConstructString: String;
  251.   var
  252.     TS,PS  : String;
  253.     Len, lngth, i,j: integer;
  254.     Segment, Offset, Typ :word;
  255.     Mask : string;
  256.     Dummyint : ^integer;
  257.     DummyLong: ^longint;
  258.     DummyReal: ^real;
  259.     DummyStr : ^string;
  260.     DummyChar: ^char;
  261.  
  262. {--- count the number of delimeters
  263.      ex: '(###)###-####' would return 3 - one each for the parentheses
  264.      and one for the dash ---}
  265.  
  266. function InValids(Msk:string): integer;
  267. var
  268.   i, count: integer;
  269.  
  270. begin
  271.   count := 0;
  272.   for i := 1 to length(Msk) do
  273.     if not(Msk[i] in MaskSet) then inc(count);
  274.   InValids := count;
  275. end;
  276.  
  277. {--- Insert the delimeters in the string;
  278.      ex: Mask = '##/##', PStr = '1234'
  279.      then InsertMask will change PStr to 12/34 ---}
  280.  
  281. procedure InsertMask(Msk: string; var PStr: string);
  282. var
  283.  i,j : integer;
  284. begin
  285.   i := 1;
  286.   for j := 1 to length(Msk) do
  287.     if (Msk[j] in MaskSet) then begin
  288.       Msk[j] := Pstr[i];
  289.       inc(i);
  290.     end;
  291.   PStr := Msk;
  292. end;
  293.  
  294. begin
  295.   TS := '';
  296.   PS := '';
  297.   List := FrontNode;
  298.   PointKey := Pad(PointKey,length(KeyMask));
  299.   InsertMask(KeyMask,PointKey);
  300.   if PointKey <> '' then TS := ' '+PointKey+' ';
  301.   while (list <> nil) do begin
  302.     Segment := List^.Segment;
  303.     Offset  := List^.Offset;
  304.     Typ := List^.Typ;
  305.     Mask := List^.Mask;
  306.     PS := '';
  307.     case Typ of
  308.       1 : begin {string}
  309.             DummyStr := ptr(segment,offset);
  310.             PS := DummyStr^;
  311.             PS := Pad(PS,length(mask));
  312.             InsertMask(Mask,PS);
  313.           end;
  314.     2,3 : begin {longint,integer}
  315.              case Typ of
  316.              3: begin
  317.                   DummyLong:= ptr(segment,offset);
  318.                   PS := Long2Str(DummyLong^);
  319.                   PS := LeftPadCh(PS,'0',Length(Mask)-InValids(Mask));
  320.                 end;
  321.              2: begin
  322.                   DummyInt := ptr(segment,offset);
  323.                   PS := Long2Str(DummyInt^);
  324.                   PS := LeftPadCh(PS,'0',Length(Mask)-InValids(Mask));
  325.                 end;
  326.              end;
  327.              InsertMask(Mask,PS);
  328.              PS := Pad(PS,Length(Mask));
  329.           end;
  330.       4: begin {real}
  331.            DummyReal := ptr(segment,offset);
  332.            PS := Form(Mask,DummyReal^);
  333.          end;
  334.       5: begin {char}
  335.            DummyChar := ptr(segment,offset);
  336.            PS:= DummyChar^;
  337.            PS := Pad(PS,Length(Mask));
  338.            InsertMask(Mask,PS);
  339.          end;
  340.     end;
  341.     TS := TS+' ';
  342.     TS := TS+' '+PS;
  343.     List := List^.next;
  344.    end;
  345.    TS := copy(TS,1,width-2);
  346.    ConstructString := TS+' ';
  347.    PointKey := SaveKey;
  348. end;
  349.  
  350. procedure DisplayFieldsLo;
  351. begin
  352.   FastWrite(ConstructString,Line,NewX-1,MainWAttr);
  353. end;
  354.  
  355. procedure DisplayFieldsHi;
  356. begin
  357.     FastWrite(ConstructString,Line,NewX-1,BarAttr);
  358. end;
  359.  
  360. {----- Display the first page in the box -----}
  361.  
  362. procedure FillWindow;
  363.   begin
  364.     Line := Y+1;
  365.     while OK and (Line < (Y+Depth)) do begin
  366.       NextKey(KFile,DatRef,PointKey);
  367.       if OK then GetRec(DFile,DatRef,Rcrd);
  368.       if OK then DisplayFieldsLo;
  369.       inc(Line);
  370.     end;
  371.     ClearKey(KFile);
  372.     NextKey(KFile,DatRef,PointKey);
  373.     if OK then GetRec(DFile,DatRef,Rcrd);
  374.     Line := Y+1;
  375.     DisplayFieldsHi;
  376.     Line := Y+1;
  377. end;
  378.  
  379. procedure Home;
  380. begin
  381.   ClearBox;
  382.   ClearKey(KFile);
  383.   FillWindow;
  384.   TmpKy := PointKey;
  385. end;
  386.  
  387.   procedure Endd;
  388.   var
  389.      i,j : integer;
  390.  
  391.   begin
  392.     ClearBox;
  393.     i := 1; j := 1;
  394.     Line := Y+1;
  395.     ClearKey(KFile);
  396.  
  397. {----- Go to EOF and back up one page -----}
  398.     repeat
  399.       PrevKey(KFile,DatRef,PointKey);
  400.       inc(i);
  401.     until (i = (Depth)) or (not OK);
  402.     OK := true;
  403. {----- Save the first display key -----}
  404.     SaveKey := PointKey;
  405.     if DupKeys then SaveRef := DatRef;
  406.     if OK then begin
  407.       GetRec(DFile,DatRef,Rcrd);
  408.       DisplayFieldsHi;
  409.     end;
  410.     inc(Line);
  411.     SearchKey(KFile,DatRef,SaveKey);
  412.     if DupKeys and (SaveRef<>DatRef) then
  413.       repeat
  414.         NextKey(KFile,DatRef,PointKey);
  415.       until SaveRef=DatRef;
  416.  
  417. {----- Display the page from the current pointer -----}
  418.     repeat
  419.       NextKey(KFile,DatRef,PointKey);
  420.       if OK then GetRec(DFile,DatRef,Rcrd);
  421.       if OK then DisplayFieldsLo;
  422.       inc(Line); inc(j);
  423.     until (i-1=j) or (not OK);
  424.     Line := Y+1;
  425.  
  426. {----- Get and display the top of page pointer -----}
  427.     FindKey(KFile,DatRef,SaveKey);
  428.     if DupKeys and (SaveRef<>DatRef) then
  429.       repeat
  430.         NextKey(KFile,DatRef,PointKey);
  431.       until SaveRef=DatRef;
  432.     if OK then GetRec(DFile,DatRef,Rcrd);
  433.   end;
  434.  
  435.   procedure SearchString(S:String);
  436.   begin
  437.     if WindowIsActive(SubWin) then
  438.       WindowsOn := SetTopWindow(Main)
  439.     else
  440.       WindowsOn := DisplayWindow(Main);
  441.     ClearBox;
  442.  
  443. {----- Find the first key >= the input string and display it ----}
  444.     SearchKey(KFile,DatRef,S);
  445.     if OK then begin
  446.       GetRec(DFile,DatRef,Rcrd);
  447.       PointKey := S;
  448.       DisplayFieldsHi;
  449.       Inc(Line);
  450.  
  451. {----- Display the rest of the page -----}
  452.       while OK and (Line < (Y+Depth)) do begin
  453.         NextKey(KFile,DatRef,PointKey);
  454.         if OK then begin
  455.           GetRec(DFile,DatRef,Rcrd);
  456.           DisplayFieldsLo;
  457.           inc(Line);
  458.         end;
  459.       end;
  460.       Line := Y+1;
  461.       SearchKey(KFile,DatRef,S);
  462.       if OK then GetRec(DFile,DatRef,Rcrd);
  463.  
  464. {---- if search goes to EOF then list the last page -----}
  465.     end else begin
  466.       PrevKey(KFile,DatRef,PointKey);
  467.       GetRec(DFile, DatRef,Rcrd);
  468.       DisplayFieldsHi;
  469.     end;
  470.  
  471.   end;
  472.  
  473.   procedure Search;
  474.   var
  475.     S, NewS   : String;
  476.     count,i,j : integer;
  477.     Escaped   : boolean;
  478.  
  479.   begin
  480.     Line := Y+1;
  481.     S := ' ';
  482.     S := Trim(S);
  483.     NewS := '';
  484.     count := 1;
  485. {----- Get the search string; Display the string as it is entered -----}
  486.     ReadString(' ',24,54,15,MainFAttr,MainFAttr,count,Escaped,S);
  487.     if WindowIsActive(SubWin) then
  488.       WindowsOn := SetTopWindow(Main)
  489.     else
  490.       WindowsOn := DisplayWindow(Main);
  491.     ClearBox;
  492.  
  493. {----- Find the first key >= the input string and display it ----}
  494.     SearchKey(KFile,DatRef,S);
  495.     if OK then begin
  496.       GetRec(DFile,DatRef,Rcrd);
  497.       PointKey := S;
  498.       DisplayFieldsHi;
  499.       Inc(Line);
  500.  
  501. {----- Display the rest of the page -----}
  502.       while OK and (Line < (Y+Depth)) do begin
  503.         NextKey(KFile,DatRef,PointKey);
  504.         if OK then begin
  505.           GetRec(DFile,DatRef,Rcrd);
  506.           DisplayFieldsLo;
  507.           inc(Line);
  508.         end;
  509.       end;
  510.       Line := Y+1;
  511.       SearchKey(KFile,DatRef,S);
  512.       if OK then GetRec(DFile,DatRef,Rcrd);
  513.  
  514. {---- if search goes to EOF then list the last page -----}
  515.     end else begin
  516.       PrevKey(KFile,DatRef,PointKey);
  517.       GetRec(DFile, DatRef,Rcrd);
  518.       DisplayFieldsHi;
  519.     end;
  520.  
  521. {------ Empty Keyboard buffer upon exit  -----}
  522.     if CheckKbd(KeyWord) then
  523.       KeyWord := ReadKeyWord;
  524.   end;
  525.  
  526.  
  527.   Procedure PageDown;
  528.   var
  529.     i : integer;
  530.  
  531.   begin
  532.     i := 1;
  533.     ClearBox;
  534.  
  535. {----- get the next page pointer -----}
  536.     while OK and (i < Depth-1) and (i < Depth+Y-Line) do begin
  537.       NextKey(KFile,DatRef,PointKey);
  538.       inc(i);
  539.     end;
  540.     Line := Y + 1;
  541.  
  542. {----- Save the top of page pointer -----}
  543.     SaveKey := PointKey;
  544.     if DupKeys then SaveRef := DatRef;
  545.  
  546.     if OK then
  547.       GetRec(DFile,DatRef,Rcrd);
  548.     DisplayFieldsHi;
  549.  
  550.  {----- Display the rest of the page -----}
  551.       while OK and (Line < Depth+Y-1) do begin
  552.         inc(Line); inc(i);
  553.         NextKey(KFile,DatRef,PointKey);
  554.         if OK then begin
  555.           GetRec(DFile,DatRef,Rcrd);
  556.           DisplayFieldsLo;
  557.         end;
  558.       end;
  559.  
  560. {----- Get the saved top of page pointer -----}
  561.  
  562.       FindKey(KFile,DatRef,SaveKey);
  563.       if DupKeys and (DatRef <> SaveRef) then
  564.        repeat
  565.          NextKey(KFile,DatRef,PointKey);
  566.         until (DatRef=SaveRef);
  567.       Line := Y+1;
  568.  
  569. {----- if EOF then go back to last record to prevent
  570.        going back to the top of file                -----}
  571.       if not OK then begin
  572.         PrevKey(KFile,DatRef,PointKey);
  573.         if OK then GetRec(DFile,DatRef,Rcrd);
  574.       end;
  575.   end;
  576.  
  577. procedure PageUp;
  578.   var
  579.     i : integer;
  580.  
  581.   begin
  582.     i := 1;
  583.     ClearBox;
  584.  
  585. {----- Get the top of page pointer -----}
  586.  
  587.     while OK and (i < Depth+Line-Y-2) do begin
  588.       PrevKey(KFile,DatRef,PointKey);
  589.       inc(i);
  590.     end;
  591.  
  592. {----- If top of file then display the first page -----}
  593.     if not OK then begin
  594.       Line := Y+1;
  595.       OK := True;
  596.       Home;
  597.     end else
  598.     begin
  599.       Line := Y+1;
  600.  
  601. {----- Save the top of page pointer -----}
  602.       SaveKey := PointKey;
  603.       if DupKeys then SaveRef := DatRef;
  604.  
  605. { ----- Hilite the the first display record -----}
  606.       if OK then begin
  607.         GetRec(DFile,DatRef,Rcrd);
  608.         DisplayFieldsHi;
  609.       end;
  610.  
  611. {----- Display the rest of the page -----}
  612.       while OK and (Line < Depth+Y-1) do begin
  613.         inc(Line); inc(i);
  614.         NextKey(KFile,DatRef,PointKey);
  615.         if OK then begin
  616.           GetRec(DFile,DatRef,Rcrd);
  617.           DisplayFieldsLo;
  618.         end;
  619.       end;
  620.  
  621. {----- Get the top of page pointer -----}
  622.       FindKey(KFile,DatRef,SaveKey);
  623.       if DupKeys and (SaveRef<>DatRef) then
  624.         repeat
  625.           NextKey(KFile,DatRef,PointKey);
  626.         until (SaveRef=DatRef);
  627.       Line := Y+1;
  628.  
  629. {----- If top of file then reset the pointer to top of file to
  630.        prevent wrapping back to the top of file -----}
  631.        if not OK then begin
  632.          NextKey(KFile,DatRef,PointKey);
  633.          if OK then GetRec(DFile,DatRef,Rcrd);
  634.       end;
  635.     end;
  636.   end;
  637.  
  638.  
  639.  
  640.   procedure ScrollUp;
  641.   begin
  642.      PrevKey(KFile,DatRef,PointKey);
  643.      if OK then GetRec(DFile,DatRef,Rcrd);
  644.      if not OK then NextKey(KFile,DatRef,PointKey)
  645.      else
  646.  
  647. {----- if at the top of the box -----}
  648.        begin
  649.          if ((Line = Y+1) and OK) then
  650.            begin
  651.              NextKey(KFile,DatRef,PointKey);
  652.  
  653. {----- Redisplay the old fields with normal attributes -----}
  654.              if OK then begin
  655.                GetRec(DFile,DatRef,Rcrd);
  656.                DisplayFieldsLo;
  657.              end;
  658.  
  659. {-----  scroll the display area -----}
  660.              PrevKey(KFile,DatRef,PointKey);
  661.              if OK then GetRec(DFile,DatRef,Rcrd);
  662.              ScrollWindowDown(x+1,y+1,x+width-1,Y+depth-1,1);
  663.              DisplayFieldsHi;
  664.           end
  665.  
  666. {----- Move up one line -----}
  667.        else
  668.          begin
  669.            ChangeAttribute(Width-1,Line,1+x,MainWAttr);
  670.            Dec(Line);
  671.            ChangeAttribute(Width-1,Line,1+x,BarAttr);
  672.          end;
  673.      end;
  674.    end;
  675.  
  676.  
  677.   procedure ScrollDn;
  678.  
  679.   begin
  680.     NextKey(KFile,DatRef,PointKey);
  681.     if OK then GetRec(DFile,DatRef,Rcrd);
  682.     if not OK then PrevKey(KFile,DatRef,PointKey)
  683.     else
  684.  
  685. {----- if at the bottom of the box  -----}
  686.        begin
  687.          if ((Line > (Y+Depth-2)) and OK)  then
  688.            begin
  689.              PrevKey(KFile,DatRef,PointKey);
  690.  
  691. {----- redisplay the current fields with normal attributes -----}
  692.              if OK then begin
  693.                GetRec(DFile,DatRef,Rcrd);
  694.                DisplayFieldsLo;
  695.              end;
  696.  
  697. {-----  scroll the display area -----}
  698.              NextKey(KFile,DatRef,PointKey);
  699.              if OK then GetRec(DFile,DatRef,Rcrd);
  700.              ScrollWindowUp(x+1,y+1,x+width-1,Y+depth-1,1);
  701.              if OK then DisplayFieldsHi;
  702.           end
  703.        else
  704.  
  705. {----- if not at the bottom of the box....-----}
  706.          begin
  707.            ChangeAttribute(Width-1,Line, 1+x,MainWAttr);
  708.            inc(Line);
  709.            ChangeAttribute(Width-1,Line,1+x,BarAttr);
  710.          end;
  711.        end;
  712.   end;
  713.  
  714. procedure CheckCoordinates;
  715. begin
  716.   if y > 18 then y := 18;
  717.   if y < 4 then y := 4;
  718.   if x < 1 then x := 1;
  719.   if x > 74 then x := 74;
  720.   if Y+Depth > 22 then Depth := 21-y;
  721. end;
  722.  
  723. begin  { Look}
  724.   HiddenCursor;
  725. {----- Get the address of the data field -----}
  726.  
  727.   KeyMask := Expand(KeyMask);
  728.   ParseFldStr;
  729.   Complete := False;
  730.   PointKey := '';
  731.   CheckCoordinates;
  732.   DisplayMain;
  733.   NewX := X+2;
  734.   Line := Y+1;
  735.   if KFile.AllowDuplKeys then DupKeys := true else DupKeys := false;
  736.   if InKey[0] = '0' then begin
  737.     ClearKey(KFile);
  738.  
  739. {----- X is where the left box line is drawn; leave a space -----}
  740.  
  741.     NextKey(KFile,DatRef,PointKey);
  742.     Home;
  743.     ClearKey(KFile);
  744.     NextKey(KFile,DatRef,PointKey);
  745.     if OK then GetRec(DFile,DatRef,Rcrd);
  746.  
  747. {----- Y is where the top box line is drawn; start on the next line -----}
  748.  
  749.     TmpKy := PointKey;
  750.   end
  751.   else
  752.     SearchString(InKey);
  753.   repeat
  754.     if CheckKbd(KeyWord) then
  755.       begin
  756.         if Lo(KeyWord) = 0 then
  757.           begin
  758.             KeyWord := ReadKeyWord;
  759.             case Hi(KeyWord) of
  760.               UpKey  : ScrollUp;
  761.               DwnKey : ScrollDn;
  762.               HomKey : Home;
  763.               EndKey : Endd;
  764.               PgUpKey: PageUp;
  765.               PgDnKey: PageDown;
  766.             end;
  767.           end
  768.         else
  769.           begin
  770.             if WindowIsActive(Main) then
  771.               WindowsOn := SetTopWindow(SubWin)
  772.             else
  773.               WindowsOn := DisplayWindow(SubWin);
  774.             if Lo(KeyWord) <> CRKey then
  775.               Search
  776.             else
  777.               begin
  778.                 Complete := True;
  779.  
  780. {---------- Empty Keyboard buffer upon exit from function----------}
  781.  
  782.                 if CheckKbd(KeyWord) then
  783.                   KeyWord := ReadKeyWord;
  784.               end;
  785.           end;
  786.       end;
  787.   until Complete;
  788.   SubWin := EraseTopWindow;
  789.   DisposeWindow(SubWin);
  790.   Main := EraseTopWindow;
  791.   DisposeWindow(Main);
  792.   Look := DatRef;
  793.   NormalCursor;
  794.   DisposeList;
  795. end;
  796.  
  797. procedure InitializeDefaults;
  798. begin
  799.   if CurrentDisplay <> MonoHerc then begin
  800.     MainWAttr := 30;
  801.     MainFAttr := 30;
  802.     MainHAttr := 30;
  803.     EditWAttr := 30;
  804.     EditFAttr := 30;
  805.     EditHAttr := 30;
  806.     BarAttr   := 63;
  807.   end else begin
  808.     MainWAttr := 7;
  809.     MainFAttr := 7;
  810.     MainHAttr := 7;
  811.     EditWAttr := 7;
  812.     EditFAttr := 7;
  813.     EditHAttr := 7;
  814.     BarAttr   := 15;
  815.   end;
  816.   MainHeader := '';
  817.   EditHeader := '';
  818. end;
  819.  
  820. begin
  821.  InitializeDefaults;
  822. end.