delphi - 如何将 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, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, 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 时,程序可以正常运行两次或更多次。
此致,
解决方案
推荐阅读
- regex - 正则表达式匹配多行中最后一次出现的字符串
- selenium-webdriver - Selenium WebDriver - 无法连接到 Mozilla geckodriver
- r - 将多个不完整的列“汇总”为 1 个汇总列
- regex - Symfony 3 access_control 正则表达式
- c++ - 为什么带有 WM_LBUTTONDBLCLK 的 PostMessage 不起作用?
- python - 在 Django 中链接更新和获取方法以更新字段
- jestjs - 如何嘲笑 api 调用以进行 saga 测试
- c# - CSOM C# 与 Project Server 连接
- javascript - 具有来自外部角度 7 的值的抽象控制
- algorithm - 如果我们将输入加倍 7*n^3