每次执行到Message1.CreateMHTMLBody('c:\Test.htm',cdoSuppressNone,'','');,出现异常“无效的语法”,请问这是什么原因。在线等待。IMessage,IConfiguration,这两个接口,在CDOSYS.dll中。procedure TForm1.SaveWholePage;
var
  Message1: IMessage;
  Configuration1: IConfiguration;
begin
  try
    Message1:= CreateComObject(CLASS_Message) as IMessage;
    Configuration1:= CreateComObject(CLASS_Configuration) as IConfiguration;
    Message1.Configuration := Configuration1;
    Message1.CreateMHTMLBody('c:\Test.htm',cdoSuppressNone,'','');
    Message1.GetStream.SaveToFile('c:\Test.mht', adSaveCreateOverWrite);
  finally
    Message1:=nil;
    Configuration1:=nil;
  end;
end;

解决方案 »

  1.   

    http://www.delphipages.com/tips/copyview.cfm?ID=209
    Saving Full Internet Explorer pages as MHT...
    This is a Delphi conversion of the routine contributed by Onega 
    found at http://codeguru.earthweb.com/ieprogram/SaveWholePage.html
     
    MrBaseball34
     
    //***********************************************************************
    // If you don't have these typelibs, import them.
    //***********************************************************************
    uses Winndows, ..., ADODB_TLB, CDO_TLB;
     
    //***********************************************************************
    // SaveWholePage -
    //   Procedure to save entire web page as MHT file.
    //
    //   Parameters:
    //   AURL - URL for file to be saved
    //   AFileName - MHT FileName you want web page saves.
    //   AView - Allows you to view the MHT in TWebBrowser
    //   AViewer - WebBrowser control to view the page in.
    //
    //***********************************************************************
    procedure SaveWholePage
      ( AURL:               String
      ; AFileName:       TFileName
      ; AView:              Boolean
      ; AViewer:           TWebBrowser
      );
    var
      LMsg: IMessage;
      LConf: IConfiguration;
      LFlds: Fields;
      LStrm: _Stream;
    begin
      LMsg := CoMessage.Create;
      LConf := CoConfiguration.Create;
      try
        LMsg.Configuration := LConf;
        LMsg.CreateMHTMLBody(AURL, cdoSuppressAll, '', '');
        LStrm := LMsg.GetStream;
        LStrm.SaveToFile(AFileName, adSaveCreateOverWrite);
      finally
        LMsg := nil;
        LConf := nil;
        LStrm := nil;
        if AView then
          AViewer.Navigate(AFileName);
      end;
    end;
      

  2.   

    也可參看這個貼http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=190155
    谁能真正的实现将htm另存为mht文件,高分相送!
      

  3.   

    还是执行到LMsg.CreateMHTMLBody(AURL, cdoSuppressAll, '', '');出现异常“无效的语法”我觉得这个方法应该是可行的,只是不知道问题处在什么地方,按常理这个调用没理由出问题的。
      

  4.   

    一個反應, 不知對不對, 你先試下>>'c:\Test.htm'
    'file://c:\Test.htm'
      

  5.   

    >>对了,万分感谢!!能不能告诉我为什么。这种问题答案还真是不好找
    因为我以前试过,代码是可以的!
    你又说不行, 那只能用 'file://' 试下了!
    我们在 IE 也是这样打开
      

  6.   

    //用OleVariant就不用声明那些接口了,呵呵~~
    uses ComObj;function MhtText(mURL: string): string;
    var
      vCDOMessage: OleVariant;
    begin
      vCDOMessage := CreateOleObject('CDO.Message');
      vCDOMessage.Configuration := CreateOleObject('CDO.Configuration');
      try
        vCDOMessage.CreateMHTMLBody(mURL);
        Result := vCDOMessage.GetStream.ReadText;
      except
        raise;
      end;
      vCDOMessage := NULL;
    end; { MhtText }function MhtFile(mURL: string; mFileName: string): Boolean;
    var
      vCDOMessage: OleVariant;
    begin
      vCDOMessage := CreateOleObject('CDO.Message');
      vCDOMessage.Configuration := CreateOleObject('CDO.Configuration');  Result := True;
      try
        vCDOMessage.CreateMHTMLBody(mURL, cdoSuppressNone);
        vCDOMessage.GetStream.SaveToFile(mFileName, $00000002);
      except
        Result := False;
      end;
      vCDOMessage := NULL;
    end; { MhtFile }//Example
    procedure TForm1.BitBtn1Click(Sender: TObject);
    begin
      MhtFile('http://www.eping.net/fourm/index.asp', 'c:\temp\temp.mht');
    end;