Dll 能为主程序提供模块化吗?

发布于 2024-08-16 16:42:37 字数 851 浏览 5 评论 0原文

简单任务: 我想制作一个程序(parent.exe)。有三个按钮。当我点击Button1时,Form1出现;当按钮2时,出现Form2;当Button3,Form3出现时...

Form1,Form2,Form3存储在三个不同的dll中(Form1dll.dll,Form2dll.dll,Form3dll.dll)。

我想让父程序(parent.exe)模块化运行。我计划添加和删除dll,但是Parent.exe要求所有dll都存在,否则会发生异常。

我该如何解决这个问题?

感谢

这里是来自parent.exe的代码:

  procedure ShowForm1;stdcall;external 'Project1dll.dll' name 'ShowForm1';
  procedure ShowForm2;stdcall;external 'Project2.dll' name 'ShowForm2';
  procedure ShowForm3;stdcall;external 'Project3.dll' name 'ShowForm3';

var
  ParentForm: TParentForm;

implementation

{$R *.DFM}



procedure TParentForm.Button1Click(Sender: TObject);
begin
  ShowForm1;
end;

procedure TParentForm.Button2Click(Sender: TObject);
begin
  ShowForm2;
end;

procedure TParentForm.Button3Click(Sender: TObject);
begin
  ShowForm3;
end;

Simple task:
I would like to make a program (parent.exe). There are three buttons. When I click Button1, Form1 appears; when Button 2, Form2 appears; when Button3, Form3 appears...

Form1, Form2, Form3 are stored in three different dlls (Form1dll.dll, Form2dll.dll, Form3dll.dll).

I wanted to make parent program (parent.exe) run modular. I planned to add and remove dlls, but Parent.exe requires all dlls to be present, otherwise an exception occures.

How can I solve the problem?

Thanx

Here is code from parent.exe:

  procedure ShowForm1;stdcall;external 'Project1dll.dll' name 'ShowForm1';
  procedure ShowForm2;stdcall;external 'Project2.dll' name 'ShowForm2';
  procedure ShowForm3;stdcall;external 'Project3.dll' name 'ShowForm3';

var
  ParentForm: TParentForm;

implementation

{$R *.DFM}



procedure TParentForm.Button1Click(Sender: TObject);
begin
  ShowForm1;
end;

procedure TParentForm.Button2Click(Sender: TObject);
begin
  ShowForm2;
end;

procedure TParentForm.Button3Click(Sender: TObject);
begin
  ShowForm3;
end;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

糖果控 2024-08-23 16:42:37

按照您的设置方式,程序会在加载时查找 DLL。您需要的是将 DLL 设置为插件。查看 JVCL 中的 JVPlugin 框架。它正是您正在寻找的东西。

The way you've got it set up, the program looks for the DLLs at load time. What you need is to set the DLLs up as plugins. Take a look at the JVPlugin framework in the JVCL. It has exactly what you're looking for.

很酷不放纵 2024-08-23 16:42:37

是的,可以通过让 EXE 使用 LoadLibrary 和 GetProcAddress 动态加载 DLL。请参阅 http://www.scalabium.com/faq/dct0130.htm 了解例子。

接下来,您可能会遇到其他问题,因为 EXE 和不同 DLL 之间不共享内存管理器和类型。您可能需要格外小心来规避这些问题或寻找解决方案。就像 运行时包/BPL特殊内存管理器

Yes it can by having the EXE Dynamically load the DLLs using LoadLibrary and GetProcAddress. See http://www.scalabium.com/faq/dct0130.htm for an example.

Next you might run into other problems because the memory manager and types are not shared between the EXE and the different DLLs. You might need to take extra care to circumvent these problems or look for solutions. Like runtime packages/BPLs or special memory managers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文