求助高手:帮忙看个问题呀!! ( 积分: 100 )

  • 主题发起人 主题发起人 diddy
  • 开始时间 开始时间
D

diddy

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure DoParse(ss: TStream);<br>var<br> &nbsp;initDone: Boolean;<br> &nbsp;htmlDoc: IHTMLDocument2;<br> &nbsp;pPersist: IPersistStreamInit;<br> &nbsp;pMS: IMarkupServices;<br> &nbsp;pMkStart: IMarkupPointer;<br> &nbsp;pMkFinish: IMarkupPointer;<br> &nbsp;pMC: IMarkupContainer;<br> &nbsp;pDoc: IHTMLDocument2;<br> &nbsp;stream: TStringStream;<br> &nbsp;sHTML: WideString;<br>begin<br> &nbsp;stream := nil;<br> &nbsp;initDone := Succeeded(CoInitialize(nil));<br> &nbsp;if not initDone then Exit;<br> &nbsp;try<br> &nbsp; &nbsp;stream := TStringStream.Create('');<br> &nbsp; &nbsp;stream.CopyFrom(ss, ss.Size);<br> &nbsp; &nbsp;if (stream.Size &lt;= 0) then raise Exception.Create('MemoryStream create failed!');<br> &nbsp; &nbsp;sHTML := stream.DataString;<br> &nbsp; &nbsp;CoCreateInstance(CLASS_HTMLDocument,<br> &nbsp; &nbsp; &nbsp;nil,<br> &nbsp; &nbsp; &nbsp;CLSCTX_INPROC_SERVER,<br> &nbsp; &nbsp; &nbsp;IID_IHTMLDocument2,<br> &nbsp; &nbsp; &nbsp;htmlDoc);<br> &nbsp; &nbsp;if Assigned(htmlDoc) then begin<br> &nbsp; &nbsp; &nbsp;htmlDoc.QueryInterface(IID_IPersistStreamInit, pPersist);<br> &nbsp; &nbsp; &nbsp;if Assigned(pPersist) then begin<br> &nbsp; &nbsp; &nbsp; &nbsp;pPersist.InitNew;<br> &nbsp; &nbsp; &nbsp; &nbsp;pPersist._Release;<br> &nbsp; &nbsp; &nbsp; &nbsp;htmlDoc.QueryInterface(IID_IMarkupServices, pMS);<br> &nbsp; &nbsp; &nbsp; &nbsp;if Assigned(pMS) then begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pMS.CreateMarkupPointer(pMkStart);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pMS.CreateMarkupPointer(pMkFinish);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pMS.ParseString(Word(sHTML[1]), 0, pMC, pMkStart, pMkFinish);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if Assigned(pMC) then begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pMC.QueryInterface(IID_IHTMLDocument2, pDoc);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if Assigned(pDoc) then begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ////////////////////////////////<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // and now,take my job -- search keyword<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//ParseDocument(pDoc);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pDoc._Release;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pMC._Release;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (pMkStart &lt;&gt; nil) then pMkStart._Release;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (pMkFinish &lt;&gt; nil) then pMkFinish._Release;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pMS._Release;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp;pPersist._Release;<br> &nbsp; &nbsp; &nbsp; &nbsp;pPersist._Release;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;htmlDoc._Release;<br> &nbsp; &nbsp;end;<br> &nbsp;finally<br> &nbsp; &nbsp;if Assigned(stream) then Freeandnil(stream);<br> &nbsp; &nbsp;if initDone then CoUninitialize;<br> &nbsp;end;<br>end;<br><br>// 多次执行DoParse之后,就出内存死锁啦,代码是从VC源码里翻译过来的,不知道那里不妥当,累死我了
 
procedure DoParse(ss: TStream);<br>var<br> &nbsp;initDone: Boolean;<br> &nbsp;htmlDoc: IHTMLDocument2;<br> &nbsp;pPersist: IPersistStreamInit;<br> &nbsp;pMS: IMarkupServices;<br> &nbsp;pMkStart: IMarkupPointer;<br> &nbsp;pMkFinish: IMarkupPointer;<br> &nbsp;pMC: IMarkupContainer;<br> &nbsp;pDoc: IHTMLDocument2;<br> &nbsp;stream: TStringStream;<br> &nbsp;sHTML: WideString;<br>begin<br> &nbsp;stream := nil;<br> &nbsp;initDone := Succeeded(CoInitialize(nil));<br> &nbsp;if not initDone then Exit;<br> &nbsp;try<br> &nbsp; &nbsp;stream := TStringStream.Create('');<br> &nbsp; &nbsp;stream.CopyFrom(ss, ss.Size);<br> &nbsp; &nbsp;if (stream.Size &lt;= 0) then raise Exception.Create('MemoryStream create failed!');<br> &nbsp; &nbsp;sHTML := stream.DataString;<br> &nbsp; &nbsp;CoCreateInstance(CLASS_HTMLDocument,<br> &nbsp; &nbsp; &nbsp;nil,<br> &nbsp; &nbsp; &nbsp;CLSCTX_INPROC_SERVER,<br> &nbsp; &nbsp; &nbsp;IID_IHTMLDocument2,<br> &nbsp; &nbsp; &nbsp;htmlDoc);<br> &nbsp; &nbsp;if Assigned(htmlDoc) then begin<br> &nbsp; &nbsp; &nbsp;htmlDoc.QueryInterface(IID_IPersistStreamInit, pPersist);<br> &nbsp; &nbsp; &nbsp;if Assigned(pPersist) then begin<br> &nbsp; &nbsp; &nbsp; &nbsp;pPersist.InitNew;<br> &nbsp; &nbsp; &nbsp; &nbsp;pPersist._Release;<br> &nbsp; &nbsp; &nbsp; &nbsp;htmlDoc.QueryInterface(IID_IMarkupServices, pMS);<br> &nbsp; &nbsp; &nbsp; &nbsp;if Assigned(pMS) then begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pMS.CreateMarkupPointer(pMkStart);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pMS.CreateMarkupPointer(pMkFinish);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pMS.ParseString(Word(sHTML[1]), 0, pMC, pMkStart, pMkFinish);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if Assigned(pMC) then begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pMC.QueryInterface(IID_IHTMLDocument2, pDoc);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if Assigned(pDoc) then begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ////////////////////////////////<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // and now,take my job -- search keyword<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//ParseDocument(pDoc);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pDoc._Release;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pMC._Release;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (pMkStart &lt;&gt; nil) then pMkStart._Release;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (pMkFinish &lt;&gt; nil) then pMkFinish._Release;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pMS._Release;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp;pPersist._Release;<br> &nbsp; &nbsp; &nbsp; &nbsp;pPersist._Release;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;htmlDoc._Release;<br> &nbsp; &nbsp;end;<br> &nbsp;finally<br> &nbsp; &nbsp;if Assigned(stream) then Freeandnil(stream);<br> &nbsp; &nbsp;if initDone then CoUninitialize;<br> &nbsp;end;<br>end;<br><br>// 多次执行DoParse之后,就出内存死锁啦,代码是从VC源码里翻译过来的,不知道那里不妥当,累死我了
 
救命呀!!!
 
读别人的代码是件很头疼的问题,直接把问题帖出来不是更好
 
最好用自己思考的方式去提问,如果只是修改代码,将VC变<br>Delphi或VB,是没意义的。
 
procedure DoParse(ss: TStream);<br>var<br> &nbsp;initDone: Boolean;<br> &nbsp;htmlDoc: IHTMLDocument2;<br> &nbsp;pPersist: IPersistStreamInit;<br> &nbsp;pMS: IMarkupServices;<br> &nbsp;pMkStart: IMarkupPointer;<br> &nbsp;pMkFinish: IMarkupPointer;<br> &nbsp;pMC: IMarkupContainer;<br> &nbsp;pDoc: IHTMLDocument2;<br> &nbsp;stream: TStringStream;<br> &nbsp;sHTML: WideString;<br>begin<br> &nbsp;stream := nil;<br> &nbsp;initDone := Succeeded(CoInitialize(nil));<br> &nbsp;if not initDone then Exit;<br> &nbsp;try<br> &nbsp; &nbsp;stream := TStringStream.Create('');<br> &nbsp; &nbsp;stream.CopyFrom(ss, ss.Size);<br> &nbsp; &nbsp;if (stream.Size &lt;= 0) then raise Exception.Create('MemoryStream create failed!');<br> &nbsp; &nbsp;sHTML := stream.DataString;<br> &nbsp; &nbsp;CoCreateInstance(CLASS_HTMLDocument,<br> &nbsp; &nbsp; &nbsp;nil,<br> &nbsp; &nbsp; &nbsp;CLSCTX_INPROC_SERVER,<br> &nbsp; &nbsp; &nbsp;IID_IHTMLDocument2,<br> &nbsp; &nbsp; &nbsp;htmlDoc);<br> &nbsp; &nbsp;if Assigned(htmlDoc) then begin<br> &nbsp; &nbsp; &nbsp;htmlDoc.QueryInterface(IID_IPersistStreamInit, pPersist);<br> &nbsp; &nbsp; &nbsp;if Assigned(pPersist) then begin<br> &nbsp; &nbsp; &nbsp; &nbsp;pPersist.InitNew;<br> &nbsp; &nbsp; &nbsp; &nbsp;pPersist._Release; //这里不对,._Release了后面还用她<br> &nbsp; &nbsp; &nbsp; &nbsp;htmlDoc.QueryInterface(IID_IMarkupServices, pMS);<br> &nbsp; &nbsp; &nbsp; &nbsp;if Assigned(pMS) then begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pMS.CreateMarkupPointer(pMkStart);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pMS.CreateMarkupPointer(pMkFinish);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pMS.ParseString(Word(sHTML[1]), 0, pMC, pMkStart, pMkFinish);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if Assigned(pMC) then begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pMC.QueryInterface(IID_IHTMLDocument2, pDoc);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if Assigned(pDoc) then begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ////////////////////////////////<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // and now,take my job -- search keyword<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//ParseDocument(pDoc);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pDoc._Release;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pMC._Release;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (pMkStart &lt;&gt; nil) then pMkStart._Release;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (pMkFinish &lt;&gt; nil) then pMkFinish._Release;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pMS._Release;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp;pPersist._Release; //这里不对,.前面已经_Release了<br> &nbsp; &nbsp; &nbsp; &nbsp;pPersist._Release; &nbsp;//这里不对,.第二次_Release了<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;htmlDoc._Release;<br> &nbsp; &nbsp;end;<br> &nbsp;finally<br> &nbsp; &nbsp;if Assigned(stream) then Freeandnil(stream);<br> &nbsp; &nbsp;if initDone then CoUninitialize;<br> &nbsp;end;<br>end;
 
后退
顶部