通过一个html页面,调用activex。html页面的charset=gb2312,运行时需要先下载图片到某个盘的文件夹下,现在由于有中文名图片,下载不成功。
function DownloadFile(Source, Dest: string): Boolean;
begin
  try
    
    Result := UrlDownloadToFile(nil, PChar(source), PChar(Dest), 0, nil) = 0;
  except
    Result := False;
  end;
end;
以上是下载写的方法。后来找了点资料改成下面的代码
function DownloadFile(Source, Dest: string): Boolean;
begin
  try
    
    Result := UrlDownloadToFile(nil, PChar(urlencode(utf8encode(source))), PChar(urlencode(utf8encode(Dest))), 0, nil) = 0;
  except
    Result := False;
  end;
end;
还是不行。请大家指教一下有什么好的办法。另说明:应要求中文名文件不能改为英文名

解决方案 »

  1.   

    Uses URLMon, ShellApi; 
    function DownloadFile(SourceFile, DestFile: string): Boolean; 
    begin 
    try 
    Result := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0, nil) = 0; 
    except 
    Result := False; 
    end; 
    end; procedure TForm1.Button1.Click(Sender: TObject); 
    const 
    // URL Location 
    SourceFile := http://www.google.com/intl/de/images/home_title.gif; 
    // Where to save the file 
    DestFile := c:\temp\google-image.gif; 
    begin 
      if DownloadFile(SourceFile, DestFile) then 
      begin 
        ShowMessage(Download succesful!); 
        // Show downloaded image in your browser 
    ShellExecute(Application.Handle,PChar(open),PChar(DestFile),PChar(),nil,SW_NORMAL) 
      end 
      else 
      ShowMessage(Error while downloading + SourceFile) 
    end; 
      

  2.   

    這樣就可以了,pchar(urlencode(utf8encode(strDownloadFile)))
      

  3.   

    我不是后来改成
    UrlDownloadToFile(nil, PChar(urlencode(utf8encode(source))), PChar(urlencode(utf8encode(Dest))), 0, nil) = 0;
    还是不行吗?
      

  4.   

    直接引用Uses URLMon,不要寫那個function,它本身就有這個方法。然後直接pchar(urlencode(utf8encode(strDownloadFile)))即可
      

  5.   

    那麼你再把utf8encode換成AnsiToUTF8、Gb2312ToUnicode試試看
      

  6.   

    谢谢,试过把utf8encode換成AnsiToUTF8、Gb2312ToUnicode还是不行
      

  7.   

    URL 用 AnsiToUtf8
    返回的html 用 Utf8ToAnsi
      

  8.   

    呵呵,楼主都被回帖转晕了,代码页和编码转换其实很简单,但是一般都自己被自己转晕了,给你做了个例子,应该是你要的。uses
      HTTPApp, IdURI  TIdURI.URLEncode('http://192.168.0.2/从未试过拥有.APE')
      结果:http://192.168.0.2/%E4%BB%8E%E6%9C%AA%E8%AF%95%E8%BF%87%E6%8B%A5%E6%9C%89.APE  UTF8ToString(HTTPDecode('http://192.168.0.2/%E4%BB%8E%E6%9C%AA%E8%AF%95%E8%BF%87%E6%8B%A5%E6%9C%89.APE'))
      结果: http://192.168.0.2/从未试过拥有.APE
      

  9.   

    谢谢大家的帮忙。我已经用最简单的办法解决了。还是用这个办法UrlDownloadToFile(nil, PChar(source), PChar(Dest), 0, nil) = 0;
    。只不过我在服务端上方的文件名都改成英文名,下载保存到自己电脑上用中文名表示就可以了。