delphi 7编写的代码查看编辑器对注释的着色
2014-01-14 19:23
375 查看
procedure TForm1.RichEdit1Change(Sender: TObject); var point: TPoint; x, x1, y, i, i1, i2, i3, i4, p: Integer; s1: string; pa: array[1..10] of char; begin (********鼠标位置和焦点位置保存*********) x := point.X; y := point.Y; x1 := RichEdit1.SelStart; (*对注释进行删除时,对注释删除后的前半部分恢复常规并且字体加黑设置,如:'(*'删除'*'后'('部分要恢复常规并且字体加黑*) i := 0; p := Length(RichEdit1.Text); RichEdit1.SelStart := i; RichEdit1.SelLength := p; RichEdit1.SelAttributes.Style := []; RichEdit1.SelAttributes.Color := clBlack; //变量赋初值 i := 0; i1 := 0; p := 0; ////////////////////////////////////////////////////////////////////////////// (*******注释"{"和"}"的渲染*************************) while p >= 0 do begin i := 0; p := 0; i := PosEx('{', RichEdit1.Text, i1) - 1; p := PosEx('}', RichEdit1.Text, i1); if i > 0 then begin if (p = 0) or (p < i) then begin p := Length(RichEdit1.Text); end; end; if p <> 0 then begin i1 := p + 1; s1 := (copy(RichEdit1.Text, i, 1)); pa[1] := s1[1]; if (not (pa[1] in [''''])) and (not (pa[1] in ['"'])) or (i < p) then begin RichEdit1.SelStart := i; RichEdit1.SelLength := p - i; Richedit1.SelAttributes.Color := clGreen; RichEdit1.SelAttributes.Style := [fsItalic]; end; end else Break; end; ////////////////////////////////////////////////////////////////////////////// //变量赋初值 i := 0; i1 := 0; p := 0; (*******注释"(*"和'*)"的渲染 ********************************************) while p >= 0 do begin i := 0; p := 0; i := PosEx('(*', RichEdit1.Text, i1) - 1; p := PosEx('*)', RichEdit1.Text, i1); if i > 0 then begin if (p = 0) or (p < i) then begin p := Length(RichEdit1.Text); end; end; if p <> 0 then begin i1 := p + 2; s1 := (copy(RichEdit1.Text, i, 1)); pa[1] := s1[1]; if (not (pa[1] in [''''])) and (not (pa[1] in ['"'])) or (i < p) then begin RichEdit1.SelStart := i; RichEdit1.SelLength := p - i + 1; Richedit1.SelAttributes.Color := clGreen; RichEdit1.SelAttributes.Style := [fsItalic]; end; end else Break; end; //////////////////////////////////////////////////////////////////////////////// (********************(注释'//"的渲染)*****************************************) i := 0; i1 := 0; i2 := 0; i3 := 0; i4 := 0; p := 0; i := PosEx('//', RichEdit1.Text, i1); if i > 0 then begin while i > 0 do begin i3 := 0; i := PosEx('//', RichEdit1.Text, i1); i1 := i + 3; begin RichEdit1.SelStart := i - 1; i4 := SendMessage(Richedit1.handle, EM_LINEFROMCHAR, Richedit1.selstart, 0); if i4 >= 0 then begin for i2 := 0 to i4 do begin i3 := i3 + Length(RichEdit1.Lines[i2]) + 2; //DBRichEdit显示时用i3 := i3 + Length(RichEdit1.Lines[i2]); end; RichEdit1.SelLength := i3 - i; Richedit1.SelAttributes.Color := clGreen; RichEdit1.SelAttributes.Style := [fsItalic]; end; end; end; end; (********鼠标位置和焦点位置重新植入*******************************************) point.X := x; point.Y := y; RichEdit1.SelStart := x1; RichEdit1.SetFocus; end;
相关文章推荐
- delphi 7编写的代码查看编辑器对保留字的着色
- Delphi 程序员代码编写标准指南
- 如何在 "万一的 Delphi 博客" 回复自动格式化的着色代码?
- 编写高质量代码改善C#程序的157个建议——建议153:若抛出异常,则必须要注释
- 编写一个函数,实现把C/C++程序代码中的注释去掉,并把结果返回。
- 编写可读代码的艺术(四)注释的“艺术性”
- 一个Javascript 编写的代码编辑器
- Delphi代码编写标准指南
- Delphi 6 程序员代码编写标准指南一
- 【插件开发】—— 9 编辑器代码分块着色-高亮显示!
- Windows XP系统用还原点启动后 Delphi 7代码编辑器的保留字显示问题修复
- delphi代码编辑器行号显示方法
- Delphi编辑器的“代码完成”功能
- Delphi程序员代码编写标准指南
- iOS 代码添加注释(按Alt + 鼠标左键可查看)
- Java编写去除代码文件中的注释以及空格、换行,并写入目标文件中
- Delphi 程序员代码编写标准指南
- 在编写xsd文件时,不能使用xml注释,否则会导致NetBeans没有代码提示功能
- 编写可维护的javascript代码--- 2015.11.22(注释)
- ArcGIS 字段编辑器,编写简单python代码