Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Delphi, RichEdit, Find method

Posted on 2011-02-18
10
Medium Priority
?
1,588 Views
Last Modified: 2012-05-11
Hi,
I Have a Special requirement. I am Using Delphi 7. I am loading some text/RTF files on RichEdit Component. I am hi liting the searched Word on the RichEdit.

For Example, I am Searching for "SQL Server", it Shows the Words in RTF. My Requirement is I have to Select Not only the given Words, Also select if there is any Special symbols within the Words. like "SQL.Server","SQL-Server" etc.

Thanks and Regards,
VIJESH V.NAIR
0
Comment
Question by:OTSSolutions
7 Comments
 
LVL 24

Accepted Solution

by:
jimyX earned 1000 total points
ID: 34925111
You can add all the special symbols that you expect in an array and search by replacing any space or non-alphabetic char in the phrase you want to find by substituting from that array one by one until you find and highlight all the similarities:
var // global var
  SpecialChar:array [1..3]of char = ('-','.','_'); // you can add any additional symbols

procedure TForm1.FindText(FindStr: string);
var X, ToEnd : integer;
    oldCursor : TCursor;
begin
   oldCursor := Screen.Cursor;
   Screen.Cursor := crHourglass;
   with RichEdit1 do
   begin
     X := 0;
     ToEnd := length(Text) ;
     X := FindText(FindStr, X, ToEnd, []) ;
     while X <> -1 do
     begin
     SetFocus;
     SelStart := X;
     SelLength := length(FindStr) ;
     SelAttributes.Color := clRed;
     X := FindText(FindStr,X + length(FindStr),ToEnd, []);
     end;
   end;
   Screen.Cursor := oldCursor;
end;

function SpecialSymbol(Ch:Char):Boolean;
begin
  if  Ch in ['a'..'z','A'..'Z'] then
    Result := False
  else
    Result := True;
end;

procedure TForm1.Button1Click(Sender: TObject) ;
var
   Str: string;
   i, j:integer;
begin
   Str := 'SQL Server';
   FindText(Str);

   for i:= 1 to length(Str) do
     begin
       if SpecialSymbol(Str[i]) then
         begin
           for j:= 1 to high(SpecialChar) do
             begin
               Str[i] := SpecialChar[j];
               FindText(Str);
             end;
         end;
     end;
end;

Open in new window

I am using the Search Function from:
http://delphi.about.com/cs/adptips2003/a/bltip0803_2.htm
0
 
LVL 32

Assisted Solution

by:Ephraim Wangoya
Ephraim Wangoya earned 1000 total points
ID: 34939795

For wild card searches, you need to use regular expressions.
Download and install TRegEx or TPerlRegEx

Using it is very easy, just set the expression, in your case could be SQL?Server
The ? will represent any character
0
 

Author Comment

by:OTSSolutions
ID: 34941685
Ok,
Thanks jimyX, and ewangoya:

Will get back to you
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35180438

I have already pointed the Author to the correct direction using Regular Expressions which can be downloaded from
http://www.regular-expressions.info/delphi.html.
Thats the way to search using wild cards
0
 
LVL 24

Expert Comment

by:jimyX
ID: 35224456
I have provided a working solution to the author's question!
0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35237248
I will not object to this but just make a note

This is class, CS Analysis of Algorithms
You have a classic example of pattern matching here, while putting in effort to develop a solution, research should be properly done on a problem before attempting to formulate a solution.

This type of question is the exact reason why we have Regular Expressions. TPerlRegEx and TRegEx are thoroughly tested and time proven methods for solving such problems.

One of the basis of OO is code reuse so we don't have to re_invent the wheel and a solution using such loops is not forward thinking neither is it expected to work under all conditions. This is the kind of coding where you have to create new application builds everyweek because some one added another search character to a search
0
 

Expert Comment

by:South Mod
ID: 35292442
All,
 
Following an 'Objection' by jimyX (at http://www.experts-exchange.com/Q_26914116.html) to the intended closure of this question, it has been reviewed by at least one Moderator and is being closed as recommended by the Expert.
 
At this point I am going to re-start the auto-close procedure.
 
Thank you,
 
SouthMod
Community Support Moderator
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question