0

How to sync Webbrowser (in Edit Mode) line with TMemo containing raw html? The position of the caret is not necessary but would be a nice feature. Plenty of google searches failed to show how to accomplish this task.

Bill
  • 2,993
  • 5
  • 37
  • 71
  • What exactly are you trying to sync? Please provide more details. – Remy Lebeau Dec 29 '11 at 23:08
  • I am trying to have the webbrowser caret match the TMemo when switching from the TMemo to the WebBrowser and have the TMemo caret match the webbrowser when switching from the Webbrowser to the TMemo. The webbrowser is in edit mode and the TMemo holds the raw HTML. So when I edit the document with webbrowser then change to the TMemo I am at the same relative position in the document as in the webbrowser document.... and vice-vera... When I switch from TMemo to the WebBrowser I want to be at about the same position in the WebBrowser document that I was in the TMemo document. – Bill Dec 30 '11 at 02:06
  • If you need more exlpanation let me know. – Bill Dec 30 '11 at 02:06
  • Something like this: case PageControl1.ActivePageIndex of 0: { TWebbrowser editor } WB.CaretPos := cxMemo1.CaretPos; 1: { TMemo } cxMemo1.CaretPos := WB.CaretPos; end; – Bill Dec 30 '11 at 02:14
  • that won't work as-is. Asside from the fact that `TWebBrowser` does not have a `CaretPos` property, you also have to remember the `TMemo` is displaying the raw HTML whereas the `TWebBrowser` is displaying the formatted text instead, so you have to take all of the HTML markup into account when translating between `WebBrowser` coordinates and `TMemo` coordinates. – Remy Lebeau Dec 30 '11 at 02:23
  • Yes I understand that. My example was to just show you what I was trying to accomplish. How about getting the webbrowser to be near the same line or is not that possible either? – Bill Dec 30 '11 at 03:05
  • I am not sure you are going to be able to do what you are asking for, at least not completely or accurately. The second article in Sam's answer shows you how to have the WebBrowser select the text of a given HTML control. You could parse the selected text in the `TMemo` to determine the name of an HTML control, then tell the WebBrowser to select the corresponding text for that control. Going the other way, call `IHTMLDocument2.selection.createRange()` and query it for the `IHTMLTxtRange` interface, retreive its `parentElement.outerHTML` text, and search for that within your `TMemo`. – Remy Lebeau Dec 30 '11 at 20:13

1 Answers1

0

It sounds like you want a way to click somewhere on an HTML page and edit the HTML source of wherever you clicked.

An internet search returned possibilities as Detect cursor position in TWebBrowser at edit mode or http://www.pcreview.co.uk/forums/re-finding-cursor-t1855943.html. These aren't Delphi specific answers but might get you started with how to interact with the DOM to do what you are looking for.

Community
  • 1
  • 1
Sam M
  • 4,136
  • 4
  • 29
  • 42
  • Thanks for the info, but it looks like this is a "tough nut-to-crack" so I have given up on the problem. – Bill Dec 30 '11 at 14:47
  • I use Dreamweaver for some of my web programming. It has the functionality you are looking for. They have an HTML preview of the code in a split window design. When you move your cursor in the preview window, it goes to the appropriate line of code. I don't know if they are using the web browser control to do the preview though. Adobe may have written their own browser control to do the preview. – Sam M Dec 31 '11 at 06:48