OSDN Git Service

Version1.86→1.00(新規)
[winbottle/winbottle.git] / sakurasuite / sample_parser / Unit1.pas
1 unit Unit1;
2
3 interface
4
5 uses
6   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7   SsParser, ComCtrls, StdCtrls;
8
9 type
10   TForm1 = class(TForm)
11     Edit1: TEdit;
12     Button1: TButton;
13     ListView1: TListView;
14     SsParser: TSsParser;
15     Edit2: TEdit;
16     Button2: TButton;
17     CheckBox1: TCheckBox;
18     CheckBox2: TCheckBox;
19     Button3: TButton;
20     Button4: TButton;
21     procedure Button1Click(Sender: TObject);
22     procedure Button2Click(Sender: TObject);
23     procedure CheckBox2Click(Sender: TObject);
24     procedure CheckBox1Click(Sender: TObject);
25     procedure Button3Click(Sender: TObject);
26     procedure Button4Click(Sender: TObject);
27   private
28     { Private \90é\8c¾ }
29   public
30     { Public \90é\8c¾ }
31   end;
32
33 var
34   Form1: TForm1;
35
36 implementation
37
38 {$R *.DFM}
39
40 procedure TForm1.Button1Click(Sender: TObject);
41 var i: integer;
42     Li: TListItem;
43 begin
44   ListView1.Items.Clear;
45   SsParser.InputString := Edit1.Text;
46   for i := 0 to SsParser.Count-1 do begin
47     Li := ListView1.Items.Add;
48     case SsParser.MarkUpType[i] of
49       mtTag:    Li.Caption := 'Tag';
50       mtTagErr: Li.Caption := 'TagErr';
51       mtMeta:   Li.Caption := 'Meta';
52       mtStr:    Li.Caption := 'Str';
53     end;
54     Li.SubItems.Add(IntToStr(i));
55     Li.SubItems.Add(SsParser[i]);
56     Li.SubItems.Add(IntToStr(SsParser.Position[i]));
57   end;
58 end;
59
60 procedure TForm1.Button2Click(Sender: TObject);
61 var i: integer;
62     Str: String;
63 begin
64   i := SsParser.Match(Edit1.Text, Edit2.Text);
65   Str := Copy(Edit1.Text, 1, i);
66   ShowMessage(IntToStr(i) + #13#10 + Str);
67 end;
68
69 procedure TForm1.CheckBox2Click(Sender: TObject);
70 begin
71   SsParser.LeaveEscape := CheckBox2.Checked;
72 end;
73
74 procedure TForm1.CheckBox1Click(Sender: TObject);
75 begin
76   SsParser.EscapeInvalidMeta := CheckBox1.Checked;
77 end;
78
79 procedure TForm1.Button3Click(Sender: TObject);
80 begin
81   try
82     ShowMessage(SsParser.GetParam(Edit1.Text, StrToInt(Edit2.Text)));
83   except
84     on EConvertError do ShowMessage('Edit2 is not Integer');
85   end;
86 end;
87
88 procedure TForm1.Button4Click(Sender: TObject);
89 var i: integer;
90     from: Int64;
91 const
92     loop = 100;
93 begin
94   from := GetTickCount;
95   for i := 1 to loop do
96     SsParser.InputString := Edit1.Text;
97   ShowMessage(Format('%d loops, %d ms.', [loop, GetTickCount - from]));
98 end;
99
100 end.