title: How To Insert a Link in a HTML Document At Runtime?
body: <p>After a lot of searching for createElement and insertAdjacentHTML on the web I came up with this code.  When the code is executed the link is not inserted into the HTML.  The link is a to a local file.  What am I doing wrong?</p>
  
  <pre><code>var
    HTMLDocument2Ifc: IHTMLDocument2;
    iLinkString: string;
    iTopicString: string;
    iLink: IHTMLElement;
  begin
    FormInsertLink := TFormInsertLink.Create( Self );
    try
      if FormInsertLink.ShowModal = mrOk then
      begin
        // &lt;A HREF="file://..\html\author.htm"&gt;Author&lt;/A&gt;
        HTMLDocument2Ifc := TopicWebBrowser1.Document as IHTMLDocument2;
        iLinkString := FormInsertLink.EditLink1.Text; // file://..\html\author.htm
        iTopicString := FormInsertLink.EditTopic1.Text; // Author
        iLink := HTMLDocument2Ifc.createElement('a');
        iLink.InnerText := iLinkString;
        iLink.insertAdjacentHTML('afterEnd', '&lt;A HREF="' + iLinkString + '"&gt;' + iTopicString + '&lt;/A&gt;');
      end;
    finally
      FormInsertLink.Free;
    end;
  </code></pre>