procedure CodeColors(Form : TForm;Style : String; RichE : TRichedit;InVisible : Boolean);
const
// symbols...
CodeC1: array[0..20] of String = ('#','$','(',')','*',',',
'.','/',':',';','[',']','{','}','<','>',
'-','=','+','''','@');
// reserved words...
CodeC2: array[0..44] of String = ('and','as','begin',
'case','char','class','const','downto',
'else','end','except','finally','for',
'forward','function','if','implementation','interface',
'is','nil','or','private','procedure','public','raise',
'repeat','string','to','try','type','unit','uses','var',
'while','external','stdcall','do','until','array','of',
'in','shr','shl','cos','div');
var
FoundAt : LongInt;
StartPos, ToEnd, i : integer;
OldCap,T : String;
FontC, BackC, C1, C2 ,C3 ,strC, strC1 : TColor;
begin
OldCap := Form.Caption;
with RichE do
begin
Font.Name := 'Courier New';
Font.Size := 10;
if WordWrap then WordWrap := false;
SelectAll;
SelAttributes.color := clBlack;
SelAttributes.Style := [];
SelStart := 0;
if InVisible then
begin
Visible := False;
Form.Caption := 'Executing Code Coloring...';
end;
end; BackC := clWhite; FontC := clBlack;
C1 := clBlack; C2 := clBlack; C3 := clBlack;
strC := clBlue; strC1 := clSilver; if Style = 'Twilight' then
begin
BackC := clBlack; FontC := clWhite;
C1 := clLime; C2 := clSilver; C3 := clAqua;
strC := clYellow; strC1 := clRed;
end
else
if Style = 'Default' then
begin
BackC := clWhite; FontC := clBlack;
C1 := clTeal; C2 := clMaroon; C3 := clBlue;
strC := clMaroon; strC1 := clSilver;
end
else
if Style = 'Ocean' then
begin
BackC := $00FFFF80; FontC := clBlack;
C1 := clMaroon; C2 := clBlack; C3 := clBlue;
strC := clTeal; strC1 := clBlack;
end
else
if Style = 'Classic' then
begin
BackC := clNavy; FontC := clYellow;
C1 := clLime; C2 := clSilver; C3 := clWhite;
strC := clAqua; strC1 := clSilver;
end
else
begin
with RichE do
begin
T := '{'+Style+' = Invalid Style [Default,Classic,Twilight,Ocean] ONLY! }';
Lines.Insert(0,T);
StartPos := 0;
ToEnd := Length(Text) - StartPos;
FoundAt := FindText(T, StartPos, ToEnd, [stWholeWord]);
SelStart := FoundAt;
SelLength := Length(T);
SelAttributes.Color := clRed;
SelAttributes.Style := [fsBold];
StartPos := 0;
ToEnd := Length(Text) - StartPos;
FoundAt := FindText('ONLY!', StartPos, ToEnd, [stWholeWord]);
SelStart := FoundAt;
SelLength := 4;
SelAttributes.Color := clRed;
SelAttributes.Style := [fsBold,fsUnderLine];
end;
end; RichE.SelectAll;
RichE.color := BackC;
RichE.SelAttributes.color := FontC; for i := 0 to 100 do
begin
with RichE do
begin
StartPos := 0;
ToEnd := Length(Text) - StartPos;
FoundAt := FindText(IntToStr(i), StartPos, ToEnd, [stWholeWord]);
while (FoundAt <> -1) do
begin
SelStart := FoundAt;
SelLength := Length(IntToStr(i));
SelAttributes.Color := C1;
SelAttributes.Style := [];
StartPos := FoundAt + Length(IntToStr(i));
FoundAt := FindText(IntToStr(i), StartPos, ToEnd, [stWholeWord]);
end;
end;
end;
for i := 0 to 20 do
begin
with RichE do
begin
StartPos := 0;
ToEnd := Length(Text) - StartPos;
FoundAt := FindText(CodeC1[i], StartPos, ToEnd, []);
while (FoundAt <> -1) do
begin
SelStart := FoundAt;
SelLength := Length(CodeC1[i]);
SelAttributes.Color := C2;
StartPos := FoundAt + Length(CodeC1[i]);
FoundAt := FindText(CodeC1[i], StartPos, ToEnd, []);
end;
end;
end;
for i := 0 to 44 do
begin
with RichE do
begin
StartPos := 0;
ToEnd := Length(Text) - StartPos;
FoundAt := FindText(CodeC2[i], StartPos, ToEnd, [stWholeWord]);
while (FoundAt <> -1) do
begin
SelStart := FoundAt;
SelLength := Length(CodeC2[i]);
SelAttributes.Color := C3;
SelAttributes.Style := [fsBold];
StartPos := FoundAt + Length(CodeC2[i]);
FoundAt := FindText(CodeC2[i], StartPos, ToEnd, [stWholeWord]);
end;
end;
end;
Startpos := 0;
with RichE do
begin
FoundAt := FindText('''', StartPos, Length(Text), []);
while FoundAt <> -1 do
begin
SelStart := FoundAt;
Startpos := FoundAt+1;
FoundAt := FindText('''', StartPos, Length(Text), []);
if FoundAt <> -1 then
begin
SelLength := (FoundAt - selstart)+1;
SelAttributes.Style := [];
SelAttributes.Color := strC;
StartPos := FoundAt+1;
FoundAt := FindText('''', StartPos, Length(Text), []);
end;
end;
end; Startpos := 0;
with RichE do
begin
FoundAt := FindText('{', StartPos, Length(Text), []);
while FoundAt <> -1 do
begin
SelStart := FoundAt;
Startpos := FoundAt+1;
FoundAt := FindText('}', StartPos, Length(Text), []);
if FoundAt <> -1 then
begin
SelLength := (FoundAt - selstart)+1;
SelAttributes.Style := [];
SelAttributes.Color := strC1;
StartPos := FoundAt+1;
FoundAt := FindText('{', StartPos, Length(Text), []);
end;
end;
end; if InVisible then
begin
RichE.Visible := True;
Form.Caption := OldCap;
end;
RichE.SelStart := 0;
end; procedure TFrmain.BitBtn1Click(Sender: TObject);
begin
CodeColors(Self, 'ss', RichEdit1, True);
end;

Delphi Richedit代码语法加亮显示的更多相关文章

  1. [转]Haroopad Markdown 编辑器代码语法高亮支持

    代码语法高亮 书写格式为: ` ` ` language_key if (condition){ return true } ` ` ` 在 ` ` ` (三个反引号)之间的是代码,其中languag ...

  2. phpBB论坛 代码 语法高亮 模块 Codebox Plus

    phpBB代码语法高亮模块 Codebox Plus Code-By.Org (https://www.phpbb.com/customise/db/mod/codebox_plus/) (https ...

  3. 怎样在WPS上实现代码语法高亮

    转载自:http://www.cnblogs.com/yuphone/archive/2009/12/13/1622901.html 小時不識月 Stupid & Hungry 本文列举两种可 ...

  4. 代码语法高亮踩坑-原理,问题, PRE元素及htmlentity

    语法高亮库基础原理 在研究使用能够在web页面上代码语法高显的解决方案时,发现有很多现成的开源库.比较中意的有prism.js,highlightjs.他们的原理基本上核心就两点: 1. 利用html ...

  5. CSS代码语法

    css 样式由选择符和声明组成,而声明又由属性和值组成,如下图所示: 选择符:又称选择器,指明网页中要应用样式规则的元素,如本例中是网页中所有的段(p)的文字将变成蓝色,而其他的元素(如ol)不会受到 ...

  6. Android 代码编辑器中实现代码语法高亮

    想写一款Android手机上的代码编辑器,实现类似c4droid中代码语法高亮 通过Android中的控件WebView中嵌入html网页,html引入CodeMirror这个第三方库就可以了,其实就 ...

  7. delphi 动态绑定代码都某个控件

    delphi 动态绑定代码都某个控件 http://docwiki.embarcadero.com/CodeExamples/Berlin/en/Rtti.TRttiType_(Delphi)Butt ...

  8. DIOCP组件(Delphi IOCP)代码阅读之ADO内存表

    DIOCP组件(Delphi IOCP)代码阅读之ADO内存表 代码中有 class procedure TADOTools.loadFromStream(pvDataSet: TCustomADOD ...

  9. ASP.NET Razor C# 和 VB 代码语法

    ylbtech-.NET: ASP.NET Razor  C# 和 VB 代码语法 Razor 不是一种编程语言.它是服务器端的标记语言. 1. C# 和 VB 代码语法返回顶部 Razor 同时支持 ...

  10. 如何写javascript代码隐藏和显示这个div

    如何写javascript代码隐藏和显示这个div 浏览次数:82次悬赏分:10 | 解决时间:2011-4-21 14:41 | 提问者:hade_girl <div id="div ...

随机推荐

  1. [转]worldwind在线加载google地图,或者基于墨卡托投影的切片地图

    package gis1; import java.net.MalformedURLException; import java.net.URL; import gov.nasa.worldwind. ...

  2. Abp vNext 扩展属性

    扩展属性 我们发现abp的默认都会有一个ExtraProperties属性,那么他的作用是什么呢?当我们使用abp的时候,需要对其原有的表进行扩展或者添加我们想要的字段,又不想改源码,以最小的方式实现 ...

  3. 字体查看比较工具 -- (采用wpf开发)

    为了进一步加深对字体文件的理解,我写了这个小工具.可以查看字体文件信息.显示字体文件包含的字体.可以从字体文件中抽取字体,保存为其子集. 加入qq群:565438497,下载最新程序. 1 显示字体文 ...

  4. 简单了解RPC实现原理-copy

    核心框架类 /* * Copyright 2011 Alibaba.com All right reserved. This software is the * confidential and pr ...

  5. jQuery详解

    目录 jQueryJS中创建对象jQuery选择器jQuery 操作 DOMjQuery 事件jQuery 动画JSON :Python工具 - pipPython工具 - VirtualEnvWEB ...

  6. 【译】轻松评估 AI 应用程序的质量

    原文 | Wendy Breiding 翻译 | 郑子铭 在构建利用 AI 的应用程序时,能够有效地评估 SLM(小型语言模型)或 LLM(大型语言模型)的响应从未如此重要. 评估是指评估 AI 模型 ...

  7. 一款由 .NET 官方团队开源的电子商务系统 - eShop

    项目介绍 eShop是一款由.NET官方开源的,基于.NET Aspire构建的用于参考学习的服务架构电子商务系统,旨在展示如何利用.NET框架及其相关技术栈构建一个现代化的电子商务网站.该项目采用服 ...

  8. 并发编程 - 线程同步(四)之原子操作Interlocked详解一

    上一章我们了解了原子操作Interlocked类的设计原理及简单介绍,今天我们将对Interlocked的使用进行详细讲解. 在此之前我们先学习一个概念--原子操作. 01.Read方法 该方法用于原 ...

  9. 2025年值得推荐的 8 款 WPF UI 控件库

    前言 今天大姚给大家分享 8 款开源.美观.功能强大.简单易用的WPF UI控件库,希望可以帮助到有需要的同学. WPF介绍 WPF 是一个强大的桌面应用程序框架,用于构建具有丰富用户界面的 Wind ...

  10. Java开发自学第一天

    Java学习日志 Day 01|2025/2/11|累计1天 今日学习时长 6小时 当日学习目标 1.了解JVM.JDK.JRE 2.学习Idea开发工具的基本使用 3.基本语法:运算符.数据类型.变 ...