tags:

views:

98

answers:

2

hi all

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;

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?

+1  A: 

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.

Ignacio Vazquez-Abrams
if i create a form in the main project and open from there the form from the dll then i'll have two forms. i tryed to set mainForm.visible:=false but it still shows
Remus Rigo
+3  A: 

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

vcldeveloper
thanks, i just modified the procedure StartApp, I changed Show to ShowModal and in the main program (dpr) I just put StartApp and it works fine. BTW is it ok if I removed Application.* procedures, it works fine without them.
Remus Rigo