打印本文 打印本文 关闭窗口 关闭窗口
CodeColor相关(二) 基类TCodeColor
作者:武汉SEO闵涛  文章来源:敏韬网  点击数2454  更新时间:2009/4/23 18:27:10  文章录入:mintao  责任编辑:mintao
ORDER="1" CELLSPACING="1" CELLPADDING="1" ''''
              + ''''width="'''' + FWidth + ''''">''''
              + ''''<TR><TD>''''
              + ''''<font face="Courier New" size="2">''''
              + FOutput
              + ''''</font>''''
              + ''''</TD></TR></TABLE>'''';
end;

//返回下一个字符
function TCodeColor.GetNextChar: Char;
begin
  inc(FPosition);
  result:=FSource[FPosition];
end;

//判断是否是字母
function TCodeColor.IsAlpha(const ch: Char): Boolean;
var
  i: Integer;
begin
  i:=ord(ch);
  if( ((i>=65)and(i<=90)) or
      ((i>=97)and(i<=122)) ) then result:=true else result:=false;
end;

//判断字符是否为多字节字符
function TCodeColor.IsMBCSChar(const ch: Char): Boolean;
begin
  Result := (ByteType(ch, 1) <> mbSingleByte);
end;

//判断是否是数字
function TCodeColor.IsNumberic(const ch: Char): Boolean;
var
  i: Integer;
begin
  i:=ord(ch);
  if(i>57) or (i<48) then result:=false else result:=true;
end;

end.

        三、子类 TCC_Delphi
        这里仅给出一个结构,Analyzer 在这暂不实现,后面会专门发一篇帖子介绍。

//┏━━━━━━━━━━━━━━┓
//┃代码着色:CodeColor v1.0  
//┃来自:悄然无声的 Blog     ┃      
//┗━━━━━━━━━━━━━━┛


unit CC_Delphi;

interface

uses
  CodeColor,StrUtils,Classes;

type
  TCC_Delphi = class(TCodeColor)
  protected
    procedure Analyzer; override;
  public
    constructor Create(const bgColor:string;width:Integer);
  end;
  

implementation

{
********************************** TCC_Delphi **********************************
}


constructor TCC_Delphi.Create(const bgColor:string;width:Integer);
begin
  inherited Create(bgColor,width);
  ReserveWords:=TStringList.Create();
  ReserveWords.LoadFromFile(''''Delphi_ReserveWords.txt'''');
end;

//字符分析函数
procedure TCC_Delphi.Analyzer;
var
  strToken:string;
  ch:Char;
begin
  
//此处暂不实现,给出部分样例仅供参考

  //.........................

  //判断标识符和关键字的情况
  if(IsAlpha(ch)  or IsMBCSChar(ch)) then
  begin
    while (IsAlpha(ch) or IsNumberic(ch) or 

上一页  [1] [2] [3]  下一页

打印本文 打印本文 关闭窗口 关闭窗口