我先做了一个main.pas 后做了一个login.pas ,现在的情况是执行程序时,最前面显示的是login页,但后面main页也显示,不用输入用户名密码,直接点击右上角的关闭就可以直接进入main页,没有起到登陆的做用,我在main.pas写了
procedure Tmain.FormActivate(Sender: TObject);
begin
 Login.Showmodal;
end;
我想实现运行程序时,先显示"登陆"页,而后面什么都没有,不输入密码就进入不了系统,
请各位帮助,先谢谢了!!

解决方案 »

  1.   

    应该改为
    procedure Tmain.FormActivate(Sender: TObject);
    begin
      if Login.Showmodal=mrcancel then
         Application.terminal;
    end;
      

  2.   

    点几确定检查密码和用户名;
    点关闭或取消则在login窗口close事件中加入main.close;不就行了。
      

  3.   

    不能在 FormActivate 中写
    在项目文件中写,如begin
      Application.Initialize;
      Application.CreateForm(TLoginForm,LoginForm);
      if LoginForm.ShowModal=mrOK then
        Application.CreateForm(TMainForm, MainForm);
      else
        Application.Terminate;
      Application.Run;
    end.
      

  4.   

    建议采用hiflower的方法,我就是用的这种方法!
    象这种登陆页面一定要在工程文件里写才叫专业!
      

  5.   

    begin
      Application.Initialize;
      Logon := TLogon.Create(Application);
      if Logon.ShowModal = mrOK then
      begin
        logon.Free;
        Application.CreateForm(TForm1, Form1);
      end
      else
        Application.Terminate;  Application.Run;
    end.
      

  6.   

    请问这段程序写在主文件的什么地方呀!我是初学!!
    begin
      Application.Initialize;
      Logon := TLogon.Create(Application);
      if Logon.ShowModal = mrOK then
      begin
        logon.Free;
        Application.CreateForm(TForm1, Form1);
      end
      else
        Application.Terminate;  Application.Run;
    end.
      

  7.   

    工程文件
    program splash;uses
      Forms,
      MainFrm in 'MainFrm.pas' {MainForm},
      SplashFrm in 'SplashFrm.pas' {SplashForm};{$R *.RES}
    begin
      Application.Initialize;
      { Create the splash screen }
      SplashForm := TSplashForm.Create(Application);
      SplashForm.Show;   // Display the splash screen
      SplashForm.Update; // Update the splash screen to ensure it gets drawn  { This while loop simply uses the TTimer component on the SplashForm
        to simulate a lengthy process. }
      while SplashForm.tmMainTimer.Enabled do
        Application.ProcessMessages;  Application.CreateForm(TMainForm, MainForm);
      SplashForm.Hide;  // Hide the splash screen
      SplashForm.Free;  // Free the splash screen
      Application.Run;
    end.
    单元1
    unit MainFrm;interfaceuses
      SysUtils, Windows, Messages, Classes, Graphics, Controls, Forms, Dialogs;type
      TMainForm = class(TForm)
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      MainForm: TMainForm;implementation{$R *.DFM}end.
    单元2
    unit SplashFrm;interfaceuses
      SysUtils, Windows, Messages, Classes, Graphics, Controls, Forms, Dialogs,
      ExtCtrls, StdCtrls;type
      TSplashForm = class(TForm)
        imgSplash: TImage;
        lbl1: TLabel;
        lbl2: TLabel;
        lbl3: TLabel;
        tmMainTimer: TTimer;
        procedure tmMainTimerTimer(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      SplashForm: TSplashForm;implementation{$R *.DFM}procedure TSplashForm.tmMainTimerTimer(Sender: TObject);
    begin
      tmMainTimer.Enabled := False;
    end;end.
      

  8.   

    login内加入main.visable:=false;
    输入用户名和密码后
    main.showm;
      

  9.   

    写在这里 ,完整的dpk文件
    program Project1;uses
      Forms,
      Controls,
      Unit1 in 'Unit1.pas' {Form1},
      Unit2 in 'Unit2.pas' {Logon};{$R *.res}begin
      Application.Initialize;
      Logon := TLogon.Create(Application);
      if Logon.ShowModal = mrOK then
      begin
        logon.Free;
        Application.CreateForm(TForm1, Form1);
      end
      else
        Application.Terminate;  Application.Run;
    end.
      

  10.   

    我是按照楼上的写的可是有错误提示如下
     [Error] STUDENT.DPR(17): Undeclared identifier: 'mrOK'
    [Error] STUDENT.DPR(24): ';' not allowed before 'ELSE'
    [Error] STUDENT.DPR(27): Record, object or class type required
    请问我哪错了呀!!
      

  11.   

    hiflower(花)的程序段有点错误呀begin
      Application.Initialize;
      Application.CreateForm(TLoginForm,LoginForm);
      if LoginForm.ShowModal=mrOK then
        Application.CreateForm(TMainForm, MainForm)   ///把这把分号去掉
      else
        Application.Terminate;
      Application.Run;
    end.
      
     
      

  12.   

    去掉else前的分号了,还是有错误提示如下
    [[Error] STUDENT.DPR(17): Undeclared identifier: 'mrOK'
    代码如下
    begin
      Application.Initialize;
      Application.CreateForm(Tf_Login,f_Login);
      if f_Login.Showmodal = mrOK then
      Application.CreateForm(Tf_Main, f_Main)
      else
        Application.Terminate;
      Application.Run;
    end.请帮助??
      

  13.   

    mrOK也许是mr_OK或许是mrOk什么的,我有好久没有用过了,不如用1代替,好象它的值相当于1,你在属性框里面去找一找也可,里面有模式对话框的返回值属性的设计项,我也是初学者,又有好久没用了,不太记得了