简体   繁体   中英

Application executes but sometimes fails to show

This is the project source:

  Application.Initialize;
  Application.MainFormOnTaskbar := False;
  Application.ShowMainForm := False;
  Application.CreateForm(TMain_Form, Main_Form);
  Application.CreateForm(TData_Module, Data_Module);
  Application.CreateForm(TForm5, Form5);
  Login;
  Application.Run;

Order of creation is : Main_Form,Data_Module,Form5

Uniconnection timeout is 30 seconds.

I am connecting to SQL Server .

And this I have in my mainForm :

procedure Login;
begin
  with TUniConnectDialog.Create(nil) do
  try
    try
      Application.MainForm.Hide;
      if not Data_Module.UniConnectDialog1.Execute then
        Application.Terminate

      else
        Application.MainForm.Show
    finally
      Free;
    end;
  except
    on E : Exception do    begin
       ShowMessage('Exception class name = '+E.ClassName);
       ShowMessage('Exception message = '+E.Message);
    end;
  end;
end;

And yet, sometimes my connect dialog fails to show and the application runs silently in the background.I have to use Windows Task Manager to end it.

I tried using eureka to debug it but it fails to show me any error. Application executes but fails to show. This happens maybe in 3 out of 10 cases. Now I cant figure out what am I doing wrong here.

Edit:

procedure Login;
begin
 with Data_Module.UniConnectDialog1.Create(nil) do
      try
      Application.MainForm.Hide;
        if not Data_Module.UniConnectDialog1.Execute then
        Application.Terminate

      else
        Application.MainForm.Show
    finally
    //  Free;
    end;
    end;

EDIT 2: This does not work either.

This is not a complete solution (or may be - hard to tell) but corrects the errors in the edit of the main question. I couldn't do it in comments, unfortunately.

procedure Login;
begin
  // with Data_Module.UniConnectDialog1.Create(nil) do
  // 1) Don't use 'with' - it just creates ambiguity
  // 2) You probably don't need to create the dialog
  // 3) If you do the format should be:
  //    Data_Module.UniConnectDialog1 := TUniConnectDialog.Create(???)
      try
      Application.MainForm.Hide;
        if not Data_Module.UniConnectDialog1.Execute then
        Application.Terminate

      else
        Application.MainForm.Show
    finally
    //  Free;
    end;
  end;    

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM