Avatar of Grant1842
Grant1842
Flag for United States of America asked on

(Advanced Expert Question Here) Get position of clicked text in twebbrowser and go to it in SynEdit(RichEdit)

I have a synedit(richedit) and a twebbrowser on a form. I have html code in the richedit.
I load the html from the rich edit into twebbrowser;
I want to click on any text or object (image)in the twebbrowser  and go to that place in the code on the richedit.
I am looking for example code to do this in Delphi p7.
Editors IDEsDelphi

Avatar of undefined
Last Comment
Grant1842

8/22/2022 - Mon
Emmanuel PASQUIER

That's going to be a lot of fun. I think you should extend the zone to more experts, we could need help :
- Delphi Programming
- Internet & Delphi Programming
developmentguru

I will try to take a closer look at this later this afternoon.  I am only writing this to let you know that someone else is looking into it.
Grant1842

ASKER
This is a Hard question Does anyone have an Ideal How to do this.
Your help has saved me hundreds of hours of internet surfing.
fblack61
Emmanuel PASQUIER

Maybe with this :
http://www.programmersheaven.com/mb/delphikylix/314808/314808/webbrowser-clicked-hyperlink/?S=B20000

we could add an onclick event on every object of the page...
Grant1842

ASKER
I am getting Service Unavailable when  I click that link
Emmanuel PASQUIER

oh ? it works for me...

here is the code related to this article
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleCtrls, SHDocVw, MSHTMLEvents, MSHTML_TLB;

type
  TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    procedure FormCreate(Sender: TObject);
    procedure WebBrowser1DocumentComplete(Sender: TObject;
      const pDisp: IDispatch; var URL: OleVariant);
  private
    HTMLAnch : OleVariant;
    AnchEvents : Array Of TMSHTMLHTMLAnchorEvents2;
    Function LinkOnClick(Sender: TObject; const pEvtObj: IHTMLEventObj) : WordBool;
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
     WebBrowser1.Navigate('F:\NCS_HTML\File3.html');
end;

Function TForm1.LinkOnClick(Sender: TObject; const pEvtObj: IHTMLEventObj) : WordBool;
Begin
     pEvtObj.srcElement.innerText := 'Clicked';
End;

procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
Var aa : Byte;
begin
     HTMLAnch := WebBrowser1.OleObject.document.getElementsByTagName('A');
     For aa := 0 To HTMLAnch.length-1 Do
     Begin
          SetLength(AnchEvents, Length(AnchEvents)+1);
          AnchEvents[aa] := TMSHTMLHTMLAnchorEvents2.Create(Self);
          AnchEvents[aa].Connect(HTMLAnch.item(aa));
          AnchEvents[aa].onclick := LinkOnClick;
     End;
end;

end.

Open in new window

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Grant1842

ASKER
THanks for that . THe site was down the other day for me when I clicked on it I see its up now.
Grant1842

ASKER
I tried that and its not really what I need.........
Thanks.

With the example you posted It seems to me there should be a way to at least get in a BLOCK OF CODE or RANGE of where you clicked.
It is useless to have a twebbrowser in edit mode if you can not detect where you clicked and get close to it in the richedt so you can work on your code..........

Any experts here have an ideal to get this done ?
ASKER CERTIFIED SOLUTION
developmentguru

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Grant1842

ASKER
Thanks for your reply.
I have allready tried TEmbeddedWB and its many example but I have failed to find a way to catch the click and go to the region in the richedit source.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
developmentguru

Ah, I bellieve it should give you the means of finding out where the user clicked.  Beyond that you will need to scan your source (in the rich edit) to find the location.  This can be a lot more difficult than it would first appear.  A simple search for text will not do.

1) You will need to verify that you can get the click event from the TEmbeddedWB.
2) figure out a way to parse the source to find the relevant code.

It sounds like you are working on a web authoring tool.  Knowing what you are aiming for would help.  What type of page is this?  Pure HTML?  ASPX? What?
Grant1842

ASKER
Thanks for your help. I am working on editing joomla 1.5 templets. so it is mixed PHP/HTML.
developmentguru

Did you get the click event?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Grant1842

ASKER
Have not had time to look into it. I am currently looking into the GECKO html engine. I think it will take a couple of modules one for the active x to interface to the GECKO engine and One to get the code back into the rich edit.
THanks for your help with these questions. If the GECKO works I will accept you answer on the other question.
Grant1842

ASKER
Solution was found useing A Custom Twebbrowser.
No need for the GECKO stuff.