开发者

move project into 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;

expor开发者_运维百科ts StartApp;

my main application's contains a dpr file containing:

procedure StartAPP; external 'myDLL.dll';

begin
   StartAPP;
end;

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


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.

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.

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;

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.

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;

Regards


You haven't actually written an application, you've created a form. Your DLL shows this form and then ends, so that's all that happens. If you start a normal project and open up the .dpr file you'll get an idea of what needs to happen in order to actually start an application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜