4

Use the following representation of the function to generate a Web archive from a local html file

function TLessonConstructor2.CreateMHT( const FileName : string):boolean ;
 var
  oMSG:IMessage;
  oConfig: IConfiguration;
  sFileName: string;
  Stream: _Stream;
begin
  //CoInitializeEx(nil, COINIT_APARTMENTTHREADED);
  //CoInitialize(nil);
  try
    Result  := false;
    sFileName := ChangeFileExt(FileName, '.mht');
    DeleteFile(PAnsiChar(sFileName));
    try
    oConfig := CoConfiguration.Create();
    oMSG    := CoMessage.Create();
    oMSG.Configuration := oConfig;
    oMSG.CreateMHTMLBody(FileName,CdoSuppressNone,'','');
    Stream:=oMSG.GetStream;
    Stream.SaveToFile(sFileName,adSaveCreateOverWrite);
    Stream.Cancel;
    Stream.Close;
    Result := True;
    except
      on E: Exception do
      begin
       Result  := false;
       MessageDlg(E.Message, mtError, [mbOK], 0);
      end;
    end;
  finally
  //  CoUnInitialize;
    Stream:=nil;
    oConfig:=nil;
    oMSG:=nil;
  end;
end;

FileName - full path to the html.

After performing oMSG.CreateMHTMLBody (FileName, CdoSuppressNone,'',''); This file is locked for as long as the basic process is completed. However, this file should be removed after processing.

Any idea what the problem is?

Fatum
  • 41
  • 3

1 Answers1

3

CreateMHTMLBody requires URL so for a local file ensure preceded with file:///

CreateMHTMLBody(const URL: WideString; Flags: CdoMHTMLFlags; 
                          const UserName: WideString; const Password: WideString); safecall;
Paul Heinrich
  • 627
  • 1
  • 6
  • 15
  • `uses CDO_TLB, ADODB_TLB;` _Stream defined in ADODB_TLB unit (Active Data Objects). IMessage, IConfigurationin in CDO_TLB unit (Collaboration Data Objects). If not already created use the Import Type Library as follows and create: `CDO_TLB = C:\WINDOWS\system32\cdosys.dll` `ADO_TLB = C:\Program Files\Common Files\System\ado\msadoxx.dll` - xx version number – Paul Heinrich Oct 23 '12 at 07:16