在关闭登录表单时尝试显示的mainform

时间:2016-10-29 11:45:59

标签: delphi

这是* .dpr:

program Project1;

uses
  Vcl.Forms,
  Unit1 in 'Unit1.pas' {Form1},
  Unit2 in 'Unit2.pas' {Form2};

{$R *.res}
var
  MainForm: TForm1;

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

登录表单:

unit Unit2;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm2 = class(TForm)
    Button1: TButton;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

procedure Login;

implementation

{$R *.dfm}

Uses Unit1;


procedure Login;
begin
  with TForm2.Create(nil) do
  try
    Application.MainForm.Hide;
    if ShowModal = mrOK then
      Application.MainForm.Show
    else
      Application.Terminate;
  finally
    Free;
  end;
end;

end.

主要表格:

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

Uses Unit2;

procedure TForm1.Button1Click(Sender: TObject);
begin
Login;
end;

end.

两个按钮都设置为模态:mrOK。 登录表单不是自动创建的,而是在可用表单列表中。

问题在于: 如果您关闭登录表单(不单击按钮)一瞬间主表单显示然后关闭(当然,应用程序也关闭)。它发生得非常快。看起来像闪烁。

当我关闭登录表单时,如何宣传我的主表单尝试显示自己?

另外,设置:

Application.MainFormOnTaskbar := False;

也无济于事......

2 个答案:

答案 0 :(得分:5)

在显示登录之前,您应该使用初始化应用程序以隐藏主窗体开始,而不是隐藏主窗体。要做到这一点,只需在创建主表单之前添加Application.ShowMainForm := false

关闭登录表单后执行的

Application.Run将根据Application.ShowMainForm变量的值显示或不显示主表单,默认情况下为true。因此,这将引入闪烁,因为在应用程序终止之前将显示主窗体。

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

答案 1 :(得分:3)

将您的登录程序变为功能并更改主要代码:

var myi = 0, timex = 20;

         function f() {
         numDots =500+myi*10; maxRad = 300;minRad = 200 ; n=numDots;
         while(n--){
            currDot = {};
            currDot.radius = minRad+Math.random()*radDiff;
            currDot.radiusV = 10+Math.random()*500,
            currDot.radiusVS = (1-Math.random()*2)*0.005,
            currDot.radiusVP = Math.random()*PI,
            currDot.ang = (1-Math.random()*2)*PI;
            currDot.speed = (1-Math.random()*2);
            //currDot.speed = 1-Math.round(Math.random())*2;
            //currDot.speed = 1;
            currDot.intensityP = Math.random()*PI;
            currDot.intensityS = Math.random()*0.05;
            currDot.intensityO = 64+Math.round(Math.random()*64);
            currDot.intensityV = Math.min(Math.random()*255, currDot.intensityO);
            currDot.intensity = Math.round(Math.random()*255);
            currDot.fillColor = 'rgb('+currDot.intensity+','+currDot.intensity+','+currDot.intensity+')';
            dots.push(currDot);
            //setTimeout(function(){n++},1000);
        }
        myi++;
         if( myi < timex ){
        setTimeout( f, 500 );
    }}
    f();

我不知道你在登录表格中查到了什么。我认为你应该返回TRUE(登录传递)或FALSE作为结果,而不是试图用其他形式进行操作。