在 delphi 中使用 COM DLL - MSVCR80D.dll 错误中的访问冲突
我需要使用使用 .NET 框架创建的 DLL。 该 DLL 使 COM 可见。
我想在使用 Delphi 2006 创建的应用程序中使用此 DLL。我已执行以下步骤:
- 使用 regscr32 注册 DLL。
使用导入类型库 德尔福集成开发环境。 它创造了 _TLB.pas 文件。 TLB 文件中创建了以下签名。
函数 TValidationRequest.Process(varmeterBSN: WideString; var NICSerial: WideString; var 零件编号:WideString; var otherConfig: WideString; out returnMessage: WideString): Smallint; 开始 结果:= DefaultInterface.Process(meterBSN,NICSerial,partNumber,otherConfig,returnMessage); 结尾;
我尝试使用调用该方法 以下代码片段。
procedure TForm1.buttonClick(Sender: TObject); var valReq: TValidationRequest; s1, s2, s3, s4, s5: WideString; o: WideString; begin valReq := TValidationRequest.Create (Self); try valReq.Process (s1, s2, s3, s4, o); MessageDlg(o, mtInformation, [mbOK], 0); finally valReq := nil; end; end;
请问您能提出任何解决方案吗?
I need to use a DLL created using .NET framework. This DLL is made COM visible.
I want to use this DLL in an application created using Delphi 2006. I have followed following steps:
- Registered the DLL using regscr32.
Imported the type library using
Delphi IDE. It created
_TLB.pas file. Following signature was created in TLB file.function TValidationRequest.Process(var meterBSN: WideString; var NICSerial: WideString; var partNumber: WideString; var otherConfig: WideString; out returnMessage: WideString): Smallint; begin Result := DefaultInterface.Process(meterBSN, NICSerial, partNumber, otherConfig, returnMessage); end;
I tried to call the method using
following code snippet.
procedure TForm1.buttonClick(Sender: TObject); var valReq: TValidationRequest; s1, s2, s3, s4, s5: WideString; o: WideString; begin valReq := TValidationRequest.Create (Self); try valReq.Process (s1, s2, s3, s4, o); MessageDlg(o, mtInformation, [mbOK], 0); finally valReq := nil; end; end;
But I get following error when Process method is called.
Please can you suggest any solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试初始化
WideStrings
(s1
、s2
、s3
、s4
,也许甚至o
)。 如果我没记错的话,在设置它们之前,它们在 Delphi 中是动态的并且为零(000000000)。Try initializing the
WideStrings
(s1
,s2
,s3
,s4
, and maybe eveno
). If I recall correctly, they are dynamic in Delphi and nil (000000000) before you set them up.除了 MarkusQ 所说的之外,请注意您对
TValidationRequest
对象的内存管理不是很好。 使用Create(nil)
然后在finally
块中写入FreeAndNil(valReq)
会更干净。 现在的方式是,每次单击按钮时都会创建一个TValidationRequest
对象,并且它们都将保留在内存中,直到您销毁表单。 至少您不会出现内存泄漏,因为您将Self
传递给了构造函数,因此至少表单会负责销毁这些对象。 在您的示例中,在TForm1.buttonClick
方法结束后确实不需要保持对象处于活动状态。In addition to what MarkusQ said, note that your memory management of the
TValidationRequest
object is not so good. It would be cleaner to useCreate(nil)
and then in thefinally
-block writeFreeAndNil(valReq)
. The way it is now you create oneTValidationRequest
object every time you click the button and they will all stay in memory until you destroy the form. At least you won't get memory leaks because you passedSelf
to the constructor so at least the form will take care of destroying those objects. In your example there is really no need to keep the object alive after theTForm1.buttonClick
method has ended.