将项目移动到dll中 [英] move project into dll

查看:110
本文介绍了将项目移动到dll中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我把我的项目移植到一个DLL中,在那里我宣布了一个这样的程序。

i moved my project into a DLL and in there I declared a procedure like this

procedure StartApp;
var
   myForm : TmyForm;
begin
   myForm:=TmyForm.Create(Application);
   myForm.Show;
end;

exports StartApp;

我的主应用程序包含一个dpr文件,其中包含:

my main application's contains a dpr file containing:

procedure StartAPP; external 'myDLL.dll';

begin
   StartAPP;
end;

当我运行我的项目它打开myForm然后退出我的应用程序。任何人都可以告诉我我做错了什么?

when i run my project it opens myForm and then it exits my application. Can anyone tell me what i have done wrong?

推荐答案

您在dLL中的程序显示非模态表单,在您的调用者应用程序您没有任何消息循环代码,如果您查看由Delphi为VCL表单应用程序创建的DPR文件,您将看到类似于以下代码:

Your procedure in the dLL is showing a non-modal form, in your caller application you do not have any code for message loop, if you look at a DPR file created by Delphi for a VCL form application, you will see a code similar to this:

begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

此代码初始化应用程序,创建表单,然后运行消息循环,此消息循环迭代并处理收到的消息,直到您的应用程序终止。

This code initializes the application, creates the form, and then runs the message loop, and this message loop iterates and processes received messages until your application is terminated.

在代码中,您只是做了表单创建部分,而不是其余部分。您可以在自己的代码中使用上述代码,并用您自己的表单创建代码替换Application.CreateForm。

In your code, you just did the form creation part, not the rest of it. You can have the above code in your own code and replace Application.CreateForm with your own form creation code.

另一个选项是将DLL中的窗体显示为模态窗体。在这种情况下,您的表单将保留在屏幕上,直到您关闭它:

Another option is to show your form inside DLL as a modal form. In that case, your form will remain on the screen until you close it:

MyForm.ShowModal;

还请注意,在您当前的代码中,DLL中的Application对象不一定指向Application对象在您的呼叫者应用程序中,除非您将Application.Handle从调用者应用程序发送到DLL。

Also please take note that in your current code Application object in your DLL does not necessarily refer to Application object in your caller application, unless you send Application.Handle from caller application to the DLL.

最好将您的DLL过程更改为如下代码: p>

It is better that you change your DLL procedure to a code like this:

procedure StartApp;
begin
  with TMyForm.Create(nil) do
  try
    ShowModal;
  finally
    Free;
  end;
end;

关心

这篇关于将项目移动到dll中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆