?
Solved

WebBrowser.ExecWB(OLECMDID_FIND

Posted on 2003-03-07
4
Medium Priority
?
3,284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month9 days, 11 hours left to enroll

762 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