Search code examples
htmldelphidelphi-7twebbrowser

Delphi TWebBrowser as HTML Editor - get font properties


I am using TWebBrowser as HTML editor in Delphi7, by setting it's designMode to 'on' in OnDocumentComplete.

I know how to change font properties like bold, italic, font, color, justify, etc. I am using exeCommand with parameters

var
  htmlDoc: HTMLDocument;
  parameter: OleVariant;
begin
  (wbEditor.Document as IHTMLDocument2).ParentWindow.Focus;
  htmlDoc := wbEditor.document as HTMLDocument;
  htmlDoc.execCommand('bold', false, parameter);
  (wbEditor.Document as IHTMLDocument2).ParentWindow.Focus;
end;

Question is how to read 'Bold' and other properties when I change cursor position inside the text.

Let's asume my text is like 'foo bar'. I want to have a 'Bold button' checked when I position my cursor at FOO, but unchecked when I position it at BAR.

???


Solution

  • Hej I found a walkaround on my own, used TEmbeddedWB instead TWebBrowser, and code below on it's OnClock and OnKeyDown events

    var
      doc: IHTMLDocument2;
      sel: IHTMLSelectionObject;
      range: IHTMLTxtRange;
    begin
      doc := wb1.Doc2;
      if Assigned(Doc) then
      begin
        Sel := Doc.selection;
        if Assigned(Sel) then
        begin
          if (Sel.type_ = 'None') or (Sel.type_ = 'Text') then
          begin
            Range := Sel.createRange as IHTMLTxtRange;
    
            Caption := Range.queryCommandValue('justifyCenter');
          end;
        end;
      end;
    end;
    

    thanks myself !!