讲述如何开发一个控件,很有价值(六)[1]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 mysine 的 blog

 

ash - automatic syntax highlight (attempt 2)

[please note: i have my delphi editor colors set-to the [ocean] colour speed settings for testing purposes. this setting works well on the default richedit white background, and most tokentypes are in different colors from each other]

okay now to do some real work. most of the function have been written thereabouts. as a basis for writing this ash i'm going to use project1.dpr which comes out of mpas2rtf.zip in the yourpasedit zip file yrpasedit.zip. this is because it much smaller than yourpasedit, and thus quicker to compile.

i suggest you put the contents of the mpas2rtf.zip into a separate directory. also copy mwpas2rtf.pas to testinput.pas using the explorer shell - we'll be using this file as a sample pascal file for benchmarking.

open project1.dpr in delphi, compile project1, run it, and open the file testinput.pas by pressing [button 1] and selecting it in the [openfile dialog]. do it a number of times, and record the time taken for each once the file is stabilised in the system cache. on my system it averages about 0.47 - 0.41 seconds once its in the cache (p133 - 16m - win95b)

preparing project1's unit1.pas

now replace the contents of mpas2rtf.pas with that code in jhdpas2rtf.pas. recompile. now open up the testinput.pas sample file again by using [button 1]. as you see - we get color - but it takes a "lot" longer: 1.20-1.25 seconds.

try and speed it up if you like. you can start by commenting out the pascal-code that codes in the different font and fontsizes in tpasconversion.setrtf. recompile and run again. this time it improves a bit to 1.10-1.15. now try commenting out the code for different colors. wow - the speed decreases down to 0.49 - 0.44.

hmm. this font and color stuff really packs a punch. we may need to look at this later in more detail if things end up too slow. for the moment we'll leave the code back in full working condition (so you'll need to go back and uncomment the code).

now put the following base code into the [onchange] event of the richedit1 in unit1.pas of project1. most of this code is just based on what we have already covered elsewhere.
 
 

procedure tform1.richedit1change(sender: tobject);

var

wasselstart,wasrow,row,beginselstart,endselstart: integer;
myre: trichedit;
mypbuff: array[0..255] of char;

begin

myre             := trichedit(sender);
wasselstart      := myre.selstart;
wasrow           := myre.perform(em_linefromchar, myre.selstart, 0);
beginselstart    := myre.perform(em_lineindex, row, 0);
endselstart      := beginselstart + length(myre.lines.strings[row]);
row              := wasrow;

end;

本文关键:控件开发
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top