DHTMLEdit - Registered Users - Helpdesk
Add a picture by code.
Thread Starter: Fabrice Vendé Started: 9/4/2008 5:25 PM UTC
Replies: 2
Add a picture by code.
Hello,

How to add a picture (image) by code ?

I have to tried do it like this :

procedure TForm1.ToolButton2Click(Sender: TObject);
var
 D: IDispatch;
 ControlRange:IHTMLControlRange;
 ImgElement: IHTMLImgElement;
begin
if Editor.CanInsertImage then
 begin

     if Editor.GetDOM(D) then
     try

         Element:=(D as IHTMLDocument2).createElement('img');
         ImgElement:=(Element) as IHTMLImgElement;

         ImgElement.src:=    Lien;
         ImgElement.alt:=     Alternatif;
         ImgElement.align:=   Alignement;
         ImgElement.border:=  LargeurBordure;
         ImgElement.hspace:=  MargeHorizontale;
         ImgElement.vspace:=  MargeVerticale;
     except
     end;
 end;
end;


But it doesn't seems to work !
I know how to update a picture by code but not to add one.


Best regards,



-
Fabrice
Re: Add a picture by code.


Re: Add a picture by code.

I think you need to add the element to the correct node:

var
  D: IDispatch;
  Element: IHTMLElement;
  node, n1: IHTMLDOMNode;
begin
  if Editor.GetDOM(D) then
  begin
    node := GetActiveNode;
    Element := (D as IHTMLDocument2).createElement('BR');
    node.parentNode.insertBefore(Element as IHTMLDOMNode, node);
...