讲述如何开发一个控件,很有价值(六)(2)
2008-04-09 04:31:06来源:互联网 阅读 ()
//
end;
end;
NB: As we will be using PasCon you''''ll have to move it from being a local variable of TForm1.Button1Click to be a global variable. This will mean you''''ll have to move all the initialising:
PasCon:=TPasConversion.Create;
PasCon.UseDelphiHighlighting(3);
to a TForm1.Show, and the PasCon.Free to TForm1.Close procedure. It will still work if you only move the variable definition - but not for long... :-)
I''''ve left the code from the old ConvertReadStream in the example above to show what we "logically" still need to implement in the current context - that is manipulating the RichEdit Control directly. What we have now is the ability to cut up the current line in to different tokens, and know what type they are. We now have to add these tokens to current line with the right attributes (Fonts,Colors,Bold etc).
But wait. They are already on the line - well the text is anyway, but maybe not in the correct format (Color,Bold etc). So what actually could do is to select each token in its corresponding positon in the RichEdit control and just apply the appropriate attributes to them.
We did this back in the beginning remeber? When we set the >10 character lines to the color red. But how do we do this now? Lets look at what we have in the variables at hand when we hit "// SetRtf" the first time:
(these example uses Uni1.pas as the input file as its more interesting)
VARIABLES
01234567901234567890 Lines.Strings[R0] unit Unit1; MyPBuff unit Unit1; MyTokenState tsIdentifier MyTokenStr unit MyRun Unit1;So what we need to do is select the word ''''unit'''' in the RichEdit control, and set its attributes. We do this by setting SelStart to the position of ''''unit'''' in the RichEdit control, and SelLength to the length of the word ''''unit''''. And since ''''unit'''' is at the beginning of the current line - thats position is BeginSelStart (which I conveninently have stored in MySelStart - you''''ll see why). Lets replace the "pseudo" comment code with the following:
MyRe.SelStart := MySelStart;
MyRe.SelLength := Length(MyTokenStr);
MyRe.SelAttributes.Assign(PasCon.FParseFont[MyTokenState]);end;
But remember we are in a loop - when we go around again we''''ll have the next token in the line, and the variables will look like this:
VARIABLES
01234567901234567890 Lines.Strings[R0] unit Unit1; MyPBuff unit Unit1; MyTokenState tsSpace MyTokenStr (space character) MyRun Unit1;But (space character) isn''''t at BeginSelStart (#0) in the RichEdit control. Its further along (at position #4). Which just happens to be BeginSelStart Length(''''unit''''). We need to update MySelStart after we process the preceeding token, but before we go around the loop again:
MySelStart := MySelStart Length(MyTokenStr);
end;
Okay - this is where we are standing at the moment:
var
WasSelStart,WasRow,Row,BeginSelStart,EndSelStart: Integer;
MyRe : TRichEdit;
MyPBuff: array[0..255] of char;
MyTokenStr:string;
MyTokenState:TTokenState;
MyRun:PChar;
MySelStart: Integer;
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com IDC资讯:
主机资讯
注册资讯
托管资讯
vps资讯
网站建设
网站运营:
建站经验
策划盈利
搜索优化
网站推广
免费资源
网络编程:
Asp.Net编程
Asp编程
Php编程
Xml编程
Access
Mssql
Mysql
其它
服务器技术:
Web服务器
Ftp服务器
Mail服务器
Dns服务器
安全防护
软件技巧:
其它软件
Word
Excel
Powerpoint
Ghost
Vista
QQ空间
QQ
FlashGet
迅雷
网页制作:
FrontPages
Dreamweaver
Javascript
css
photoshop
fireworks
Flash
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
