unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls, Menus, ComCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Button2: TButton;<br> PageControl1: TPageControl;<br> TabSheet1: TTabSheet;<br> TabSheet2: TTabSheet;<br> RichEdit1: TRichEdit;<br> Memo1: TMemo;<br> Button3: TButton;<br> TabSheet3: TTabSheet;<br> RichEdit2: TRichEdit;<br> Label2: TLabel;<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> procedure RichEdit1KeyUp(Sender: TObject; var Key: Word;<br> Shift: TShiftState);<br> procedure Button3Click(Sender: TObject);<br> procedure RichEdit1Change(Sender: TObject);<br> procedure FormShow(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> function whether(st:string):Boolean;<br> function zuai(st:string):Boolean;<br> function zhaoqian(si:longint):longint;<br> function zhaohou(si:longint):longint;<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br> uses StrUtils,unit2;<br> var<br> filename,filename2:string;<br> yqian,yhou:longint;<br>{$R *.dfm}<br>function TForm1.whether(st:string):Boolean;<br>var<br> i:longint;<br> s:string;<br>begin<br> Result:=false;<br> for i:=0 to memo1.lines.Count-1 do<br> begin//1<br> s:=trim(memo1.lines.Strings );<br> if st=s then<br> begin//2<br> Result:=true;<br> exit;<br> break;<br> end;//2<br> end;//1<br>end;<br><br>function TForm1.zuai(st:string):Boolean;<br>var<br> i:longint;<br> s:string;<br> zuaizi1:array [0..100] of string;<br>begin<br>zuaizi1[0]:=':';<br>zuaizi1[1]:='=';<br>zuaizi1[2]:='/*';<br>zuaizi1[3]:='*/';<br>zuaizi1[4]:='//';<br>zuaizi1[5]:=';';<br>zuaizi1[6]:='::';<br>zuaizi1[7]:='(';<br>zuaizi1[8]:=')';<br>zuaizi1[9]:='[';<br>zuaizi1[10]:=']';<br>zuaizi1[11]:='^';<br>zuaizi1[12]:='.';<br>zuaizi1[13]:=':';<br>zuaizi1[14]:='^.';<br>zuaizi1[15]:='*';<br>zuaizi1[16]:='/';<br>zuaizi1[17]:=',';<br>zuaizi1[18]:='"';<br>zuaizi1[19]:='{';<br>zuaizi1[20]:='}';<br>zuaizi1[21]:=')';<br>zuaizi1[22]:=#13;<br>zuaizi1[23]:=#10;<br>zuaizi1[24]:=' ';<br><br> Result:=false;<br> for i:=0 to 24 do<br> begin//1<br> if st=zuaizi1 then<br> begin//2<br> Result:=true;<br> exit;<br> break;<br> end;//2<br> end;//1<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> j,linestrlen,cishu:longint;<br> linestr,analyse,linefen2:string;<br> linepos:array of longint;<br>begin<br> cishu:=0;<br> setlength(linepos,cishu);<br> linestr:=RichEdit1.Text;<br> if linestr='' then exit;<br> linestrlen:=Length(linestr);<br> form2.Show ;<br> form2.ProgressBar2.Progress :=0;<br> form2.ProgressBar2.MaxValue := linestrlen;<br> analyse:='';<br> for j:=1 to linestrlen do<br> begin//2<br> application.ProcessMessages ;<br> form2.ProgressBar2.Progress := form2.ProgressBar2.Progress +1;<br> <br> linefen2:=linestr[j];<br> if zuai(linefen2) then<br> begin//3<br> setlength(linepos,cishu+1);<br> linepos[cishu]:=j;<br> if cishu-1>=0 then<br> begin//4<br> RichEdit1.SelStart :=linepos[cishu-1];<br> RichEdit1.SelLength :=linepos[cishu]-RichEdit1.SelStart-1;<br> end//4<br> else<br> begin//5<br> RichEdit1.SelStart :=0;<br> RichEdit1.SelLength :=linepos[cishu]-1;<br> end;//6<br> if whether(analyse) then<br> begin//4<br><br> form2.Edit1.Text :=analyse;<br> form2.Edit1.Update ;<br><br> RichEdit1.SelAttributes.Color := clblue;<br> RichEdit1.SelAttributes.Style := [fsBold];<br> end//4<br> else<br> begin//6<br><br> form2.Edit1.Text :=linefen2;<br> form2.Edit1.Update ;<br><br> RichEdit1.SelAttributes.Color := clBlack;<br> RichEdit1.SelAttributes.Style := [];<br> end;//6<br> inc(cishu);<br> analyse:='';<br> end//3<br> else<br> begin//4<br> analyse:=analyse+linefen2;<br> end;//4<br> end;//2<br> form2.Close ;<br>end;<br><br><br>procedure TForm1.Button2Click(Sender: TObject);<br>var<br> i:longint;<br> s:string;<br> ass:TStringList;<br>begin<br> ass:=TStringList.Create ;<br> s:='';<br> for i:=0 to richedit1.Lines.Count -1 do<br> begin//1<br> s:=s+ richedit1.Lines.Strings +#13#10;<br> end;//1<br> ass.Clear ;<br> ass.Add (s);<br> ass.SaveToFile(filename);<br>end;<br><br><br>function TForm1.zhaoqian(si:longint):longint;<br>var<br> i,j:longint;<br> s,tmp:string;<br>begin<br> j:=0;<br> tmp:=copy(richedit1.Text,1,si-1) ;<br> for i:=si-1 downto 1 do<br> begin//1<br> if zuai(tmp) then<br> begin//2<br> j:=i+1;<br> Result:=j;<br> exit;<br> break;<br> end;//2<br> end;//1<br>end;<br><br>function TForm1.zhaohou(si:longint):longint;<br>var<br> i,j,t:longint;<br> s,tmp:string;<br>begin<br> j:=0;<br> tmp:=copy(richedit1.Text,si,length(richedit1.Text)) ;<br> tmp:=trim(tmp);<br> tmp:=tmp+' ';<br> for i:=1 to length(tmp) do<br> begin//1<br> if zuai(tmp) then<br> begin//2<br> j:=i-1;<br> t:=si+j;<br> Result:=t;<br> exit;<br> break;<br> end;//2<br> end;//1<br>end;<br><br>procedure TForm1.Button3Click(Sender: TObject);<br>var<br> i:longint;<br> s:string;<br> ass:TStringList;<br>begin<br> ass:=TStringList.Create ;<br> s:='';<br> for i:=0 to Memo1.Lines.Count -1 do<br> begin//1<br> s:=s+ Memo1.Lines.Strings +#13#10;<br> end;//1<br> ass.Clear ;<br> ass.Add (s);<br> ass.SaveToFile(filename2);<br>end;<br><br><br>procedure TForm1.RichEdit1KeyUp(Sender: TObject; var Key: Word;<br> Shift: TShiftState);<br>var<br> analyse:string;<br>begin<br>{<br> Label2.Caption :=inttostr(richedit1.CaretPos.x );<br> if (key=17) then exit;<br> if (key=39) then exit;<br> if (key=37) then exit;<br> yqian:=zhaoqian(richedit1.CaretPos.x);<br> yhou:=zhaohou(richedit1.CaretPos.x );<br>}<br>end;<br><br>procedure TForm1.RichEdit1Change(Sender: TObject);<br>var<br> analyse:string;<br>begin<br> { if yhou>yqian then<br> begin//1<br> RichEdit1.SelStart :=yqian-1 ;<br> RichEdit1.SelLength :=yhou-yqian+1;<br> analyse:=copy(richedit1.Text,yqian,yhou-yqian);<br> if whether(analyse) then<br> begin//5<br> RichEdit1.SelAttributes.Color :=clblue;<br> RichEdit1.SelAttributes.Style := [fsBold];<br> end//5<br> else<br> begin//6<br> RichEdit1.SelAttributes.Color := clBlack;<br> RichEdit1.SelAttributes.Style := [];<br> end;//6<br><br> end;//1<br> }<br>end;<br><br>procedure TForm1.FormShow(Sender: TObject);<br>var<br> s:string;<br>begin<br>s:=extractfilepath(application.ExeName );<br>if rightstr(s,1)<>'/' then<br> s:=s+'/';<br><br>s:=s+'baoliuzi.txt';<br>if fileexists(s) then<br>begin//1<br> memo1.Lines.LoadFromFile(s);<br> filename2:=s;<br>end;//1<br><br><br>s:=extractfilepath(application.ExeName );<br>if rightstr(s,1)<>'/' then<br> s:=s+'/';<br>s:=s+'a.rtf';<br>if fileexists(s) then<br>begin//1<br> richedit1.Lines.LoadFromFile(s);<br> filename:=s;<br> Button1Click(nil);<br>end;//1<br><br>end;<br><br>end.<br>