叶
叶不归
Unregistered / Unconfirmed
GUEST, unregistred user!
先说说那个com组件,接口我声明如下(一部分):<br> TBBuf = record<br> dwSize: DWORD;<br> pvBuffer: DWORD;<br> end;<br><br> TPn = record<br> HNo: Byte;<br> Hdl: DWORD;<br> end;<br><br> IApiMgr = interface(IUnknown)<br> ['{25E4A41D-59D1-4274-AE4A-30F39DAECA3E}']<br> function InitB(BnP: BAD; dwExt: DWORD; Pn: DWORD): HResult; safecall;<br> function UninitB(Pn: DWORD): HResult; safecall;<br> end;<br><br>其中<br>type BAD = (BAD_D, BAD_L, BAD_U);<br><br>public<br> BBuf: TBBuf;<br> Pn: TPn;<br> ApiMgr: IApiMgr;<br> procedure a;<br> procedure b;<br>end;<br><br>procedure TForm1.a;<br>begin<br> ApiMgr.CreateComObj(CLSID) as IApiMgr; //成功<br> BBuf.dwSize := sizeof(TPn);<br> BBuf.pvBuffer := LongInt(@Pn);<br> ApiMgr.InitB(BAD_L, 0, LongInt(@BBF)); //成功<br> (位置1)<br>end;<br><br>procedure TForm1.b;<br>begin<br> (位置2)<br> ApiMgr.UninitB(LongInt(@Pn)); //语句1 //调用时内存报错。<br>end;<br><br>怪事出现了:<br> 做法1. 把语句1放在位置1时,正常。<br> 做法2. 在位置2前加上这么一句memo1.lines.add('a:' + IntToStr(Application.Handle));<br> 就正常了。而且还一定要有(Application.Handle)这么一段,单单<br> memo1.lines.add('a:');也仍旧出错。<br><br>请问,这是为什么??<br><br>我可能表达的不是很清楚,有疑问请提出。<br>