各位高手,我想实现一个将指定网址添加到收藏夹,编译的时候没什么问题,但是一执行,就老报错,还请各位帮我看看~ 哪里出了问题? 谢谢~~procedure TForm1.Button1Click(Sender: TObject);
  const
  CLSID_ShellUIHelper:TGUID='{64AB4BB7-111E-11D1-8F79-00C04FC2FBE1}';
  var
  ShellUIHelper:ISHellUIHelper;
  url,title:Olevariant;begin
  url:='www.sohu.com';
  title:='搜狐';
  ShellUIHelper:=CreateComObject(CLSID_SHELLUIHELPER) as IShellUIHelper;
  ShellUIHelper.AddFavorite(url,title);//执行到这句报错
end;

解决方案 »

  1.   

    你没有loadlibrary当然会报错了
    procedure TForm1.AddFavorite(IE: TEmbeddedWB);
      procedure CreateUrl(AUrlPath, AUrl: PChar);
      var
      URLfile: TIniFile;
      begin
      URLfile := TIniFile.Create(String(AUrlPath));
      RLfile.WriteString('InternetShortcut', 'URL', String(AUrl));
      RLfile.Free;
      end; 
      var
      AddFav: function(Handle: THandle;
      UrlPath: PChar; UrlPathSize: Cardinal;
      Title: PChar; TitleSize: Cardinal;
      FavIDLIST: pItemIDList): Bool; stdcall;
      FDoc: IHTMLDocument2;
      UrlPath, url, title: array[0..MAX_PATH] of char;
      H: HWnd;
      pidl: pItemIDList;
      FRetOK: Bool;
      begin
      FDoc := IHTMLDocument2(IE.Document);
      if FDoc = nil then exit;
      StrPCopy(Title, FDoc.Get_title);
      StrPCopy(url, FDoc.Get_url);
      if Url <> '' then
      begin
      H := LoadLibrary(PChar('shdocvw.dll'));
      if H <> 0 then
      begin
      SHGetSpecialFolderLocation(0, CSIDL_FAVORITES, pidl);
      AddFav := GetProcAddress(H, PChar('DoAddToFavDlg'));
      if Assigned(AddFav) then
      FRetOK :=AddFav(Handle, UrlPath, Sizeof(UrlPath), Title, Sizeof(Title), pidl)
      end;
      FreeLibrary(h);
      if FRetOK then
      CreateUrl(UrlPath, Url);
      end
      end;
      

  2.   

    Url需要填写完整,如:Url := 'http://www.sohu.com';
      

  3.   

    很简单的故障,就是Url没有写完整而已.测试一下就知道了.
      

  4.   

    另外,检查下是否引用了ComObj单元
      

  5.   

    楼主说"编译的时候没什么问题",说明SHDocVw和ComObj单元都已引用, 只是运行时错误.