home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Pascal / BPASCAL.700 / D12 / GREPTV.ZIP / GREPDLG.PAS next >
Encoding:
Pascal/Delphi Source File  |  1992-10-01  |  2.7 KB  |  122 lines

  1. {************************************************}
  2. {                                                }
  3. {   Turbo Vision Grep Dialog Unit                }
  4. {   Copyright (c) 1992 by Borland International  }
  5. {                                                }
  6. {************************************************}
  7.  
  8. unit GrepDlg;
  9.  
  10. interface
  11.  
  12. uses Objects, Drivers, Views, Dialogs, Regexp;
  13.  
  14. const
  15.   roCase   = $01;
  16.   roSubDir = $02;
  17.  
  18. type
  19.   TRequest = record
  20.     Expression: String[80];
  21.     FileMask: String[12];
  22.     StartDir: String[79];
  23.     Options: Word;
  24.   end;
  25.  
  26. type
  27.   PGrepDialog = ^TGrepDialog;
  28.   TGrepDialog = object(TDialog)
  29.     constructor Init;
  30.   end;
  31.  
  32. implementation
  33.  
  34. uses Strings, MsgBox;
  35.  
  36. type
  37.   PRegexInput = ^TRegexInput;
  38.   TRegexInput = object(TInputLine)
  39.     function Valid(Command: Word): Boolean; virtual;
  40.   end;
  41.  
  42. function TRegexInput.Valid(Command: Word): Boolean;
  43. var
  44.   Exp: array[0..80] of Char;
  45.   Regex: HRegexp;
  46.   Error: Integer;
  47. begin
  48.   if (Command <> cmCancel) and (Command <> cmValid) then
  49.   begin
  50.     Regex := 0;
  51.     if Data^ <> '' then
  52.       Regex := RegComp(StrPCopy(Exp, Data^), Error);
  53.     if Regex = 0 then
  54.     begin
  55.       RegError(Regex, Error, Exp);
  56.       MessageBox('Invalid regular expression: ' +
  57.         StrPas(Exp), nil, mfError + mfOkButton);
  58.       Select;
  59.       Valid := False;
  60.     end
  61.     else
  62.       Valid := True;
  63.     RegFree(Regex);
  64.   end
  65.   else
  66.     Valid := inherited Valid(Command)
  67. end;
  68.  
  69. constructor TGrepDialog.Init;
  70. var
  71.   R: TRect;
  72.   Control: PView;
  73. begin
  74.   R.Assign(3, 4, 75, 15);
  75.   inherited Init(R, 'Search Parameters');
  76.  
  77.   { Edit }
  78.   R.Assign(15, 2, 68, 3);
  79.   Control := New(PRegexInput, Init(R, 80));
  80.   Insert(Control);
  81.   {Static  Drive}
  82.   R.Assign(3, 2, 14, 3);
  83.   Insert(New(PLabel, Init(R, '~E~xpression', Control)));
  84.  
  85.   { Edit }
  86.   R.Assign(15, 3, 68, 4);
  87.   Control := New(PInputLine, Init(R, 12));
  88.   Insert(Control);
  89.   {Static  Drive}
  90.   R.Assign(3, 3, 14, 4);
  91.   Insert(New(PLabel, Init(R, '~F~ile mask', Control)));
  92.  
  93.   { Edit }
  94.   R.Assign(15, 4, 68, 5);
  95.   Control := New(PInputLine, Init(R, 79));
  96.   Insert(Control);
  97.   R.Assign(3, 4, 14, 5);
  98.   Insert(New(PLabel, Init(R, '~D~irectory', Control)));
  99.  
  100.   {Check Button }
  101.   R.Assign(15, 6, 68, 7);
  102.   Control := New(PCheckBoxes, Init(R,
  103.     NewSItem('~C~ase sensitive     ',
  104.     NewSItem('~R~ecurse subdirectories',
  105.     nil))));
  106.   Insert(Control);
  107.   R.Assign(3, 6, 11, 7);
  108.   Insert(New(PLabel, Init(R, 'Options', Control)));
  109.  
  110.   { Button  Ok }
  111.   R.Assign(47, 8, 57, 10);
  112.   Insert(New(PButton, Init(R, 'O~K~', cmOk, bfDefault)));
  113.  
  114.   { Button Cancel }
  115.   R.Move(12, 0);
  116.   Insert(New(PButton, Init(R, 'Cancel', cmCancel, bfNormal)));
  117.  
  118.   SelectNext(False);
  119. end;
  120.  
  121. end.
  122.