讲述如何开发一个控件,很有价值(三)(4)
2008-04-09 04:31:05来源:互联网 阅读 ()
empty if no text selected, or actual text selected
SelAttribute
Default attributes if I was to start typing at the Cursor position OR the actual attributes of the selected textThere is actually no other way to access the attributes of the text already in the Control than by programmatically accessing them via manipulating Sel variables (*if you stick to using the defined properties and methods).
In the end RichEdit.Text and RichEdit.Lines are just plain old strings - not really "rich" at all. The other thing to note is that SelStart is a 0-based index on the first character of RichEdit.Text - so it looks like Richedit.Line is out the door.
7. Okay implement: Select a Token
Basically I wanted to start at the beginning of the line, send just that line to PasCon, and read it back in and replace the current line with the result. Trouble is RichEdit doesn''''t give you access to the ''''RTF'''' representation of a single line. Plus I still can''''t tell when the beginning or end of the line is. Since the latter seems to be a nagging problem, we better fix that first - trouble is: How?
When all else fails - WinAPI calls of course.
Most visual controls in Delphi are in fact just native Windows controls encapsulate as Delphi types. You can still use Windows API functions to access the control underneath. This was it is possible to access information not accessable per Delphi public Properties, Method or Events. Time to delve through Win32.HLP and see what it has to say about RichEdit controls. Its stored in C:/Program Files/Borland/Delphi 3.0/Help if you don''''t have a shortcut to it.
Open Win32.HLP -> [ Contents ] -> [ RichEdit controls ] -> [ Rich Edit Controls ]
I spent some time getting to know the "full" capabilites of the RichEdit control hidden behind Delphi''''s implementation of it. Much of what I learned came in handy later on (as you''''ll see) and as a result I derived my second two Delphi Rules:
Delphi Rule #2: If your Project hinges on the capabilities of a certain control - make sure you know everthing about it - from the beginning.
Delphi Rule #3: "Reference" is not the same as "Summary" (also known as Win32.HLP Rule#1)
Eventually I discovered the key in the [ Rich Edit Control Reference ] under "Lines and Scrolling". I had thought this page was simply a summary of the messages discussed in the preceding help pages. Actually it included a number of extra messages not discussed elsewhere - the exact ones I was after!
EM_LINEFROMCHAR - give them a 0-based index and they''''ll return the line
EM_LINEINDEX - give them a line and you get the index of the first character
EM_LINELENGTH - give them a line and you get the length of the line
So lets start coding.
(NB: To use the constants (EM-?) you''''ll have to manually add RichEdit in the uses clause)
var WasSelStart,Row,BeginSelStart,EndSelStart: Integer;
MyRe : TRichEdit;
begin
MyRe := TRichEdit(Sender);
WasSelStart := MyRE.SelStart;
Row := MyRE.Perform(EM_LINEFROMCHAR, MyRE.SelStart, 0);
BeginSelStart:= MyRe.Perform(EM_LINEINDEX, Row, 0);
EndSelStart := BeginSelStart Length(MyRE.Lines.Strings[Row]);
// I didn''''t use the EM_LINELENGTH message, as the variables was avaiable via Delphi
Edit1.Text := IntToStr(WasSelstart) ''''-''''
IntToStr(Row) ''''-''''
InttoStr(BeginSelStart) ''''-''''
IntToStr(EndSelStart);
end;
标签:
版权申明:本站文章部分自网络,如有侵权,请联系: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
