procedure TForm1.Button2Click(Sender: TObject);
var   
  d2,D:IHTMLDocument2;
  d1:IHTMLDocument;
  e:IHTMLElement;
  e2:IHTMLElement2;
  cp:IHTMLControlRange;
  img,img1:IHTMLImgElement;
  ce:IHTMLControlElement;
  myitem:Olevariant;
  i:integer;
begin     D:=   webbrowser1.Document as IHTMLDocument2;
  e:=d.body as IHTMLElement;
  e2:=e as IHTMLElement2;
  cp:=e2.createControlRange as IHTMLControlRange;
  d2:= webbrowser1.Document as IHTMLDocument2;
  myitem := WebBrowser1.Document;
    for i := 0 to D.images.length - 1 do
    begin 
           img1:=D.all.item(i,varempty) as IHTMLImgElement;
           if  img1.src='images/buttom_01_01.jpg'  then
           img:=img1 AS IHTMLImgElement;
           begin
           end;   
    end;
//  Clipboard.Assign(img as IHTMLImgElement);
 // img:=d2.images.item('images/buttom_01_01.jpg',0) AS IHTMLImgElement;
  ce:=img as IHTMLControlElement;
  cp.add(ce);
  cp.execCommand('Copy',false,0);
end;初始化如下   
  initialization   
  OleInitialize(nil);   
  finalization   
  OleUninitialize;//end.前面。   
  在uses中加入ActiveX
============================================不过运行时提示interface not supported ...不知道什么原因,,,急

解决方案 »

  1.   

    img1:=D.all.item(i,varempty) as IHTMLImgElement;改为:img1:=D.images.item(i,varempty) as IHTMLImgElement;
      

  2.   

    嗯.改了之后又出新问题了.procedure TForm1.Button2Click(Sender: TObject);
    var   
      d2,D:IHTMLDocument2;
      d1:IHTMLDocument;
      e:IHTMLElement;
      e2:IHTMLElement2;
      cp:IHTMLControlRange;
      img,img1:IHTMLImgElement;
      ce:IHTMLControlElement;
      myitem:Olevariant;
      i:integer;
    begin     D:=   webbrowser1.Document as IHTMLDocument2;
      e:=d.body as IHTMLElement;
      e2:=e as IHTMLElement2;
      cp:=e2.createControlRange as IHTMLControlRange;
      d2:= webbrowser1.Document as IHTMLDocument2;
      myitem := WebBrowser1.Document;
        for i := 0 to D.images.length - 1 do
        begin 
               img1:=D.images.item(i,varempty) as IHTMLImgElement;
               if  img1.src='images/buttom_01_01.jpg'  then
               img:=img1 AS IHTMLImgElement;
        end;
    //  Clipboard.Assign(img as IHTMLImgElement);
     ce:=img as IHTMLControlElement;
     try
     cp.add(ce);
     cp.execCommand('Copy',false,0);
     except
     end;
    end;=============================
     cp.add(ce);
    运行到这里提示无效指针,,,
    因为img 没name和id属性==========
    最原始的代码是这样的
    =============================
      var   
      d2,D:IHTMLDocument2;   
      d1:IHTMLDocument;   
      e:IHTMLElement;   
      e2:IHTMLElement2;   
      cp:IHTMLControlRange;   
      img:IHTMLImgElement;   
      ce:IHTMLControlElement;   
      begin   
      D:=   webbrowser1.Document   as   IHTMLDocument2;   
      e:=d.body   as   IHTMLElement;   
      e2:=e   as   IHTMLElement2;   
      cp:=e2.createControlRange   as   IHTMLControlRange;   
      d2:=   webbrowser1.Document   as   IHTMLDocument2;   
      img:=d2.images.item('imgname',0)   AS   IHTMLImgElement;   
      ce:=img   as   IHTMLControlElement;   
      cp.add(ce);   
      cp.execCommand('Copy',false,0);   
      end;
      

  3.   

    是不是说没有id跟name属性指针就指向不了了??
      

  4.   

    ce 是 nil 导致的, 也即没有找到你那个 'images/buttom_01_01.jpg'
      

  5.   

    好了,自己搞定了,呵呵,在此谢谢 wgqcsdn(wgq) 辛苦了.其他的各位朋友也都好样的.向你们学习.
      

  6.   

    原来src属性要求完整路径,呵呵,也就是<img src="images/d.jpg"> 但用src的时候必须为:http://..../images/d.jpg 这样才能找到,汗....