我在做管理系统,从欢迎界面进入登录界面再到主界面,我现在的主窗体是登录窗体loginform,我想把主界面mainform设为主窗体,可是一这样设置在登录时就会发生错误,是不是我的工程文件写的不对?谁能帮我分析下?在一个系统中是不是一定要把主界面设为主窗体呢?如果就用loginform作为主窗体有没影响?
我的工程文件如下:
program PersonMIS;uses
  Forms,
  UnitStartup in 'UnitStartup.pas' {StartupForm},
  UnitLogin in 'UnitLogin.pas' {LoginForm},
  UnitMain in 'UnitMain.pas' {MainForm},
  UnitDM in 'UnitDM.pas' {DM: TDataModule};{$R *.res}begin
  Application.Initialize;
  StartupForm:= TStartupForm.Create(StartupForm);
  StartupForm.Show;
  StartupForm.Update;
  Application.CreateForm(TLoginForm, LoginForm);
  Application.CreateForm(TMainForm, MainForm);
  StartupForm.Hide;
  StartupForm.Free;
  Application.CreateForm(TDM, DM);
  Application.Run;
end.

解决方案 »

  1.   

    begin
      Application.Initialize;
      Application.ShowMainForm := False;
      Application.Title := '进帐单开票系统';
      Application.CreateForm(Tmainf, mainf);
      Application.CreateForm(Tdataf, dataf);
      Application.CreateForm(Tdlf, dlf);
      Application.CreateForm(Tzprepf, zprepf);
      Application.CreateForm(Tjsrepf, jsrepf);
      Application.CreateForm(Tfjzdrepf, fjzdrepf);
      Application.CreateForm(Tjzdrepf, jzdrepf);
      Application.CreateForm(Txjzprepf, xjzprepf);
      Application.Run;
    end.
    这是我的源程序,你看看你那里写的不对!~
      

  2.   

    begin
      Application.Initialize;
      StartupForm:= TStartupForm.Create(StartupForm);
      StartupForm.ShowModal;//模式显示
      if StartupForm.ModalResult = mrOK then//ModalResult返回何值,在登陆窗体中设置
         begin
         Application.CreateForm(TLoginForm, LoginForm);
         Application.CreateForm(TMainForm, MainForm);
         Application.CreateForm(TDM, DM);
         Application.Run;
         end else Halt(0);
      end.
      

  3.   

    应该把DM先创建(我想你可能在LoginForm里存在一个东西是MAINFORM需要访问的, 你先找找,然后移到DM里begin
      Application.Initialize;
      StartupForm:= TStartupForm.Create(StartupForm);
      StartupForm.Show;
      StartupForm.Update;
      Application.CreateForm(TDM, DM);
      LoginForm := TLoginForm.Create(Application);
      StartupForm.Close;
      StartupForm.Free;
      if LoginForm.ShowModal = mrOk then
      begin
        Application.CreateForm(TMainForm, MainForm);
        Application.Run;
      end
      else
        Halt(0);end.
      

  4.   

    建议还是把主界面作为主窗体
    在主窗体的Create事件中创建、显示登陆窗体,如果登陆失败则Close
    另:DM创建应在MainForm前面,否则登陆时不能用这个DM了。
      

  5.   

    我现在工程文件是这样写的:
    program PersonMIS;uses
      Forms,
      UnitStartup in 'UnitStartup.pas' {StartupForm},
      UnitLogin in 'UnitLogin.pas' {LoginForm},
      UnitMain in 'UnitMain.pas' {MainForm},
      UnitDM in 'UnitDM.pas' {DM: TDataModule};{$R *.res}begin
      Application.Initialize;
      StartupForm:= TStartupForm.Create(StartupForm);
      StartupForm.Show;
      StartupForm.Update;
      //Application.CreateForm(TMainForm, MainForm);
      Application.CreateForm(TDM, DM);
      LoginForm := TLoginForm.Create(Application);
      StartupForm.Close;
      StartupForm.Free;
      if LoginForm.ModalResult=mrOk then
      begin
        Application.CreateForm(TMainForm, MainForm);
        Application.Run;
      end
      else
        Halt(0);end.我在登录窗体中已经设置了登录按钮的ModalResult属性为’mrOk'
    但是运行时工程文件这句"if LoginForm.ModalResult=mrOk then"
    会出现“undeclared identifier:'mrOK'的错误提示,要怎么解决啊?
      

  6.   

    我加了Controls,上面的问题已经解决了,但是运行到了欢迎界面以后又出现错误了"project personMIS.exe raised exception class EAccessViolation with message'Access violation at address 00490179 in module' personMIS.exe'.Read of address 01570EE8'.Process stopped.Use Step of Run to continue."
    麻烦高手帮我看看哪里错了?方便的话加我qq:6923317,注明CSDN,我把程序发给你们,你们帮我调试看看?
    program PersonMIS;
    begin
      Application.Initialize;
      StartupForm:= TStartupForm.Create(StartupForm);
      StartupForm.Show;
      StartupForm.Update;
      Application.CreateForm(TDM, DM);
      Application.CreateForm(TMainForm, MainForm);
      LoginForm := TLoginForm.Create(Application);
      StartupForm.Close;
      StartupForm.Free;
      if LoginForm.ModalResult=mrOk then
      begin
        Application.CreateForm(TMainForm, MainForm);
        Application.Run;
      end
      else
        Halt(0);end.
    unit UnitLogin;
    implementation
    uses UnitDM,UnitMain;
    var
      i:integer=0;
      username:string;
      sys:Boolean = false;
      aqlogin:TADOQuery;{$R *.dfm}procedure TLoginForm.FormCreate(Sender: TObject);
    var
      currentTime:real;begin
      currentTime:=GetTickCount div 1000;// GetTickCount函数返回窗口启动后过去的毫秒数,这个值除以1000 转化为秒数
      while ((GetTickCount div 1000)<(currentTime+3)) do
      {什么都不做}; //使FormLogin延时3秒打开
    end;procedure TLoginForm.BitBtn2Click(Sender: TObject);
    begin
      application.Terminate;
    end;procedure TLoginForm.BitBtn1Click(Sender: TObject);
    begin
    aqlogin:=TADOQuery.Create(nil);//创建ADO控件
    aqlogin.Connection:=DM.ADOConnection1;
    UserName:=Trim(Edit1.Text);
    AQLogin.Close;
    AQLogin.SQL.Clear;
    AQLogin.SQL.Add('Select * From Login Where UserName='+''''+UserName+'''');
    AQLogin.Open;
     if UserName<>'' then
       begin
         if AQLogin.Eof  then //用户名错误
           begin
             if i=3 then
               begin
                  ShowMessage('很抱歉,您已经输错三次用户名,系统将自动退出!');
                  application.Terminate;
               end
             else
               begin
                 ShowMessage('该用户不存在,您还有'+IntToStr(3-i)+'次机会,请重新输入正确的用户名');
                 edit1.Clear;
                 edit2.Clear;
                 edit1.SetFocus;
                 Inc(i);
               end;
           end
         else  //用户名正确
           begin
             if AQLogin.FieldByName('password').AsString=edit2.Text then //密码正确
               begin
                 if AQLogin.FieldByName('sysadmin').AsBoolean then
                   begin
                     sys:=true; //管理员权限
                     self.Close;
                     //MainForm.ShowModal;
                   end
                 else
                   begin
                     sys:=false; //普通用户权限
                     self.Hide;
                     MainForm.N10.Enabled:=false;
                     MainForm.N11.Enabled:=false;
                     MainForm.SpeedButton5.Enabled:=false;
                     MainForm.ShowModal;
                   end;
                 end
              else  //密码错误
                begin
                  ShowMessage('密码错误,请重新输入');
                  edit2.Clear;
                  edit2.SetFocus;
                end;
            end;
       end
     else
       begin
         ShowMessage('用户名不能为空,请输入');
         edit2.Clear;
         edit1.SetFocus;
       end;
    end;
    end.unit UnitMain;
    uses UnitLogin;
    implementation{$R *.dfm}procedure TMainForm.N19Click(Sender: TObject);
    begin
      Application.Terminate;   //退出程序
    end;end.