如何将 popupparent 属性传递给 DLL

问题描述

我将 popupparent 属性从程序传递给 DLL。

当对 DLL 调用两次时,程序会引发访问冲突。

这是我的dll代码:

library mydll;

uses
  System.SysUtils,System.Classes,Vcl.Forms,umydllform in 'umydllform.pas' {FormDLL};

{$R *.res}

procedure myfunction(Parent: TCustomForm); stdcall;
var
  A: TFormDLL;
begin
  A := TFormDLL.Create(nil);
  A.PopupMode := TPopupMode.pmAuto;
  A.PopupParent := Parent;
  A.ShowModal;
  A.PopupParent := nil;
  A.Free;
end;

exports
  myfunction;

begin

end.

这是主要形式:

unit umainform;

interface

uses
  Winapi.Windows,Winapi.Messages,System.SysUtils,System.Variants,Vcl.Graphics,Vcl.Controls,Vcl.Dialogs,Vcl.StdCtrls;

type
  TForm37 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  end;

var
  Form37: TForm37;

implementation

{$R *.dfm}

procedure TForm37.Button1Click(Sender: TObject);
type
  Tmyfunction = procedure(AOwner: TCustomForm); stdcall;
var
  H: HMODULE;
  F: Tmyfunction;
begin
  H := LoadLibrary(PChar('mydll.dll'));
  @F := GetProcAddress(H,'myfunction');
  F(Application.MainForm);
  FreeLibrary(H);
end;

end.

程序第一次运行正常。 但是第二次执行dll时出现异常。 我需要分配弹出式父属性,以便表单不会被遗忘。

当不使用 FreeLibrary 时,程序可以正常运行两次或更多次。

最好的问候,

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...