?
Solved

WebBrowser.ExecWB(OLECMDID_FIND

Posted on 2003-03-07
4
Medium Priority
?
3,330 Views
Last Modified: 2012-06-27
When calling WebBrowser.ExecWB(OLECMDID_FIND I get the error:
"Trying to revoke a drop targetthat has not been registered".
Other commands work fine like: OLECMDID_COPY and OLECMDID_PASTE.

Example:

procedure Search: boolean;
var
  vaIn: OleVariant;
begin
  WebBrowser.Navigate('c:\tmp\test.htm');
  vaIn := 'bla';
  WebBrowser.ExecWB(OLECMDID_SHOWFIND, OLECMDEXECOPT_DODEFAULT, vaIn);
end;

initialization
  OleInitialize(nil);

finalization
  OleUninitialize;
0
Comment
Question by:King_David
  • 2
4 Comments
 
LVL 9

Expert Comment

by:ginsonic
ID: 8092903
You can try also:

private procedure Search(aText: string);
     

procedure TForm1.Search(aText: string);
var
  i: Integer;
begin
  for i := 0 to WebBrowser1.OleObject.Document.All.Length - 1 do
  begin
    if Pos(aText, WebBrowser1.OleObject.Document.All.Item(i).InnerText) <> 0 then
    begin
      WebBrowser1.OleObject.Document.All.Item(i).Style.Color := '#FF0000';
      WebBrowser1.OleObject.Document.All.Item(i).ScrollIntoView(True);
    end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Search('bla');
end;
0
 

Accepted Solution

by:
JamesLondon earned 1000 total points
ID: 8095848
Hi,

GinSonic's code is good, however it Highlights the entire entity in which the InnerText resides. If you just want to highlight the given Text, try the following: -



Procedure HighlightText(aText: String; aColor: TColor;
 bMatchCase, bWholeWord: Boolean);
Var
 Range, Bookmark: OleVariant;
 HLStr: String;
 Flags: Integer;
 X: Integer;
begin
  Range:=((Browser.Document AS IHTMLDocument2).Body AS IHTMLBodyElement).createTextRange;
  HLStr:='<FONT COLOR="Red">' + aText + '</FONT>';

  Flags := 0;
  IF bWholeWord Then Flags := Flags + 2;
  IF bMatchCase Then Flags := Flags + 4;

  IF Range.findText(aText, 0, Flags) Then
  Begin
    {IF bScroll Then }Range.select;
    Range.PasteHTML(HLStr);
  End;

End;


Best Regards,
James
0
 
LVL 1

Author Comment

by:King_David
ID: 8109035
Thanks, this is exactly what I needed.

One problem I still have is when I call HighlightText immediately after navigate, I get
Access Violation, this probably because the document is not yet loaded.
I tried using Busy but it won't help.

David.
0
 

Expert Comment

by:JamesLondon
ID: 8112528
Hi David,

You're welcome! Thanks for the points/Grade.

Which event are you using? - If your using onNavigateComplete2 try onTitleChange instead.

Best Regards,
James
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Integration Management Part 2
Suggested Courses
Course of the Month9 days, 11 hours left to enroll

609 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