讲述如何开发一个控件,很有价值(三)(2)
2008-04-09 04:31:05来源:互联网 阅读 ()
inc(RunStr);
end;
RunStr^:= #0;
TokenStr:= FStrBuff;
end; { ScanForRtf }
EXAMPLE - code snippet from Pas2Rtf demonstrating the "long comment" bugThe problem
: if FStrBuff is enlarged using AllocStrBuff() (to make it bigger to handle a very long comment) the Windows Memory manager probably has to re-allocate it by moving the entire string buffer somewhere else in memory. RunStr however is not adjusted for this change and stillpoints to the old memory area, now unallocated.The fix: Reallocate RunStr in the AllocStrBuff routine so it points to the correct place in the new area of memory. Try and fix it yourself, or look at my garsely spaghetti code in jhdPasToRtf.pas.
Automatic Syntax Highlighting (my first implementation)
To understand how Automatic syntax highlighting works, you should have a close look at what happens in the Delphi 3.0 Editor. After all - if Borland was happy with it - who am I to argue :-)
Take note when the "syntax" changes and what is affected. In retrospect the difficult thing is to implement a highlighter that is:
- Fast
- Accurate
- Doesn''''t flicker
- Isn''''t obvious ("the someone is chasing me phenomenon".. you''''ll see)
1. When should we do the re-highlighting ?
In YourPasEdit the highlighting is done as the file is read in. Once this is done, the only way to make use of that technique would be to write out the file everytime it changes and read it back in again - obviously a very slow process. In my case, I basically wanted to just reformat the line(s) that have been changed, immediately after the change had been done i.e. after every new character, DELETE or BACKSPACE or even Paste or DragDrop had been processed. I needed something that was triggered everytime the control was effected in such a way.
What I needed then was an [Event].
2. Which event - there''''s so many to choose from ?
A RichEdit, like any control, has a number of [Events] triggered when you do various things to the control. What is not obvious, is that many events trigger other events in turn. So in choosing which Event(s) to hang your code off you have to ensure that (a) it catches all situations where you need to "fix" the highlighting and (b) it doesn''''t become re-entrant (i.e. what you do in the [Event], doesn''''t trigger itself again or any other [Event] that would call the "highlighting code"). From a quick look at the helpfile, I decided that [OnChange] seemed a likely candidate. According to the Delphi 3.0 Helpfile:
You may be thinking however: "Heh? What about those other things - like Methods and Properties. Can''''t they also change the text?" They sure can - but most end up triggering [OnChange] anyhow.
3. Is it what I want? - Rich text controls (from Delphi3 Helpfile)
By default, the rich text editor supports
- Font properties, such as typeface, size, color, bold, and italic format
- Format properties, such as alignment, tabs, indents, and numbering
- Automatic drag-and-drop of selected text
- Display in both rich text and plain text formats.
(Set PlainText to True to remove formatting)
type TNotifyEvent = procedure(Sender: TObject) of object;
property OnChange: TNotifyEvent;
4. Is it the event I want - ie [OnChange] Event - the right one?
Live dangerously, let’s give it a go and see...by testing our assumptions out:
So I wrote my first [OnChange] event:
- Create a New application
- place on it one RichEdit (RichEdit1) and one Edit control (Edit1)
- Code the [OnChange] for the RichEdit1 control like this:
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- 讲述如何开发一个控件,很有价值(七) 2008-04-09
- 讲述如何开发一个控件,很有价值(六) 2008-04-09
- 讲述如何开发一个控件,很有价值(四) 2008-04-09
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
