Reputation: 1509
I would greatly appreciate some help on anyone that has experience in working with Rich Edit controls in Delphi that support Regular Expression searches.
I've toyed around with RichEdit.dll V3 based controls only to find that MS's ITextSelection.FindText implementation uses some MS Mickey Mouse variant of regular expressions (i.e. ^p for paragraph) and so on.
Regular expression searches against TRichEdit1.text return mismatched SelStart locations due to hidden RTF formatting.
I guess this rules out any RichEdit.dll based controls/components unless someone could suggest a workaround?
I've also had a look at Dream Rich Editor but am worried that this is longer maintained (as of 2005). Otherwise, this looks ideal but cannot find any contact information to ask what ReGex syntax is supported (i.e. PCRE?)
Another option was ProfHTMLEdit but that chocked on the 2MB HTML file I tested it against. Editing was also non responsive on large files. Shame, as the control looked promising.
Yet another component was TRichView but sadly that does not appear to support searching using Regular Expressions.
Simply put, my requirement is a Delphi 7 control that allow simple editing (i.e. bold, italic, selection alignments) and most importantly, the ability the search using Regular Expressions (preferably PCRE.. but not necessarily). Not too fussed what the underlying storage mechanism (rtf, html, xyz) is.
Any help or pointers/hints/tips greatly appreciated.
Upvotes: 2
Views: 1992
Reputation: 1509
I've done some more research on TRichEdit and RichEd20.dll based on the excellent feedback to this question.
Some background. I want to use TPerlRegEx to search a TRichEdit control contents and highlight matched results. Previous attempts using RichEdit1.Lines.Text as the search subject resulted in a mismatched RegEx MatchedExpressionOffset and RichEdit1.SelStart.
I had thought that this was due to RTF formatting.. but that was just me having a brain fart!
On closer examination, there are two issue that need to be taken into consideration when not using RichEdit.FindText:
To correctly find the SelStart using TPerlRegex carriage returns and line feeds need to be taken into consideration when determining the SelStart.
Upvotes: 1
Reputation: 36850
It's strange, but most lists of regexp components for Delphi don't mention the one I use almost all of the time:
VBScript_RegExp_55_TLB.pas
gotten by importing the "Microsoft VBScript Regular Expressions 5.5" type library. It's gotten the VBScript label because it was introduced with VBScript/Javascript 5.5 together with Internet Explorer 5.5, which means you're sure end-user client have the library if you require users to have IE5.5 or above. I haven't combined it with a rich-edit control though.
Upvotes: 2
Reputation: 20132
I use TRichView, and although as you say it does not support searching using Regular Expressions, you get it with full source code.
I've made various customizations to the package for my own software, and to change the internals of the search functionality to support Regular Expressions would not be too difficult in my estimation.
That is probably true of any RichEdit control where you have the source code.
So then take a look at: "...use Regular Expressions in Delphi?" for an idea on how to add it yourself.
And I did find a user of TRichView who did implement regex. He describes a bit of how he did it, and the package he used was TRegEx. I am not familiar with TRegEx myself, but maybe he's referring to this one, or you could try using TRegExpr.
You can find a good list of RegEx libraries for Delphi on About.com.
Upvotes: 1
Reputation: 4659
This link may help. I can't speak from experience with the components mentioned there, but as a HelpScribble user of many years I can say that Jan Goyvaert's support for his products is consistently outstanding. You might try contacting him - he may know of a useful component. It does occur to me that if you copied the text from a RichEdit control to a string variable (without formatting), you may be able to search that then map that position back to the text in your control. Just a thought.
Upvotes: 2