home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue38 / Parser / unit1.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1998-07-05  |  3.0 KB  |  119 lines

  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, Buttons, StdCtrls, ExtCtrls, NewParse, Parsecmp;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     SpeedButton1: TSpeedButton;
  12.     RadioGroup1: TRadioGroup;
  13.     SpeedButton2: TSpeedButton;
  14.     OpenDialog1: TOpenDialog;
  15.     EOF: TLabel;
  16.     Memo1: TMemo;
  17.     Symbol: TLabel;
  18.     StringL: TLabel;
  19.     IntegerL: TLabel;
  20.     FloatL: TLabel;
  21.     Label6: TLabel;
  22.     Label7: TLabel;
  23.     Label8: TLabel;
  24.     Label9: TLabel;
  25.     Label10: TLabel;
  26.     Label11: TLabel;
  27.     Comment: TLabel;
  28.     Label13: TLabel;
  29.     Label14: TLabel;
  30.     OpenTag: TLabel;
  31.     CloseTag: TLabel;
  32.     SpeedButton3: TSpeedButton;
  33.     AParser: ThgsParser;
  34.     procedure SpeedButton1Click(Sender: TObject);
  35.     procedure SpeedButton2Click(Sender: TObject);
  36.     procedure FormCreate(Sender: TObject);
  37.     procedure SpeedButton3Click(Sender: TObject);
  38.     procedure AParserParse(Sender: TObject; Token: Char;
  39.       var Abort: Boolean);
  40.   private
  41.     { Private declarations }
  42.     DoAbort: boolean;
  43.   public
  44.     { Public declarations }
  45.   end;
  46.  
  47. var
  48.   Form1: TForm1;
  49.  
  50. implementation
  51.  
  52. {$R *.DFM}
  53.  
  54. procedure TForm1.SpeedButton1Click(Sender: TObject);
  55. var
  56.   AStream: TFileStream;
  57. begin
  58.   DoAbort := false;
  59.   EOF.Caption := '0';
  60.   Symbol.Caption := '0';
  61.   StringL.Caption := '0';
  62.   IntegerL.Caption := '0';
  63.   FloatL.Caption := '0';
  64.   Comment.Caption := '0';
  65.   OpenTag.Caption := '0';
  66.   CloseTag.Caption := '0';
  67.   Memo1.Lines.Clear;
  68.   AStream := TFileStream.Create(OpenDialog1.FileName, fmOpenRead);
  69.   case RadioGroup1.ItemIndex of
  70.     0: AParser.ParserType := ptCSV;
  71.     1: AParser.ParserType := ptText;
  72.     2: AParser.ParserType := ptPascal;
  73.     3: AParser.ParserType := ptEnhPas;
  74.     4: AParser.ParserType := ptHtml;
  75.   end;
  76.   try
  77.     AParser.ParseStream := AStream;
  78.   finally
  79.     AStream.Free;
  80.   end;
  81. end;
  82.  
  83. procedure TForm1.SpeedButton2Click(Sender: TObject);
  84. begin
  85.   OpenDialog1.Execute;
  86. end;
  87.  
  88.  
  89. procedure TForm1.FormCreate(Sender: TObject);
  90. begin
  91.   DoAbort := false;
  92. end;
  93.  
  94. procedure TForm1.SpeedButton3Click(Sender: TObject);
  95. begin
  96.   DoAbort := true;
  97. end;
  98.  
  99. procedure TForm1.AParserParse(Sender: TObject; Token: Char;
  100.   var Abort: Boolean);
  101. begin
  102.   Application.ProcessMessages;
  103.   Abort := DoAbort;
  104.   case Token of
  105.     toEOF: EOF.Caption := IntToStr(StrToInt(EOF.Caption)+1);
  106.     toSymbol: Symbol.Caption := IntToStr(StrToInt(Symbol.Caption)+1);
  107.     toString: StringL.Caption := IntToStr(StrToInt(StringL.Caption)+1);
  108.     toInteger: IntegerL.Caption := IntToStr(StrToInt(IntegerL.Caption)+1);
  109.     toFloat: FloatL.Caption := IntToStr(StrToInt(FloatL.Caption)+1);
  110.     toComment: Comment.Caption := IntToStr(StrToInt(Comment.Caption)+1);
  111.     toOpenTag: OpenTag.Caption := IntToStr(StrToInt(OpenTag.Caption)+1);
  112.     toCloseTag: CloseTag.Caption := IntToStr(StrToInt(CloseTag.Caption)+1);
  113.   end;
  114.   if (Sender is TCustomParser) then
  115.     Memo1.Lines.Add((Sender as TCustomParser).TokenString);
  116. end;
  117.  
  118. end.
  119.