在初始化一个窗体的时候,如果符合条件一则进入窗体A,否则进入窗体B,这种应该怎样实现?

解决方案 »

  1.   

    if xxx then //你的条件
    form1.show else form2.show;
      

  2.   

    那就在form.create里判断就好啊!
    你不是这个意思?
      

  3.   

    form.create里判断
    if xxx then //你的条件
    form1.show else form2.show;
      

  4.   

    你必须在工程文件中把A和B的窗体初始化放在另一个窗体C的前面,然后才能在C的create事件里根据条件显示你要的窗口
      

  5.   

    var
      frmFlash: TfrmFlash;
    begin
      Application.Initialize;
      frmFlash := TfrmFlash.Create(application);
      frmFlash.Show;
      frmFlash.Update;
      if frmFlash.ShowModal <> mrOk then  {满足条件,运行a窗体}
        Application.CreateForm(Tfrma, frma);
      else                                {不满足条件,运行b窗体}
        Application.CreateForm(Tfrmb, frmb);
      frmFlash.Hide;
      frmFlash.Free;
      Application.Run;
    end.
      

  6.   

    weizi2000(秋风啊):我用了你的方法,好像不行!运行后,出现一个最小化的窗口,其他什么也没有看到,还有就是计算机变得奇慢无比!我是希望先检测互联网是否连通,如果连通,并且用户名与密码正确,则进入正常使用界面,如果网络没有连通,则进入拨号的界面!请帮我看一下错在什么地方!谢谢以下是源码:unit Unit_login;interfaceuses
      Windows, Messages, winInet,SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, jpeg, ExtCtrls;type
      Tfrm_login = class(TForm)
      procedure FormShow(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;type
    TNature = (Micro,Macro);
    TMethod = Record
      Name: string[20];
      Condition: string[40];
      Nature: string[60];
      Result: string[60];
    end;
    type MethodFileType = file of TMethod;
    var
    frm_login: Tfrm_login;
    MyRec:TMethod;
    RecFile:MethodFileType;
    implementationuses unit_first, Unit_myfirst, unit_main;{$R *.dfm}
    //函数开始
    function InternetConnected: Boolean;const// local system uses a modem to connect to the Internet.INTERNET_CONNECTION_MODEM = 1;// local system uses a local area network to connect to the Internet.INTERNET_CONNECTION_LAN = 2;// local system uses a proxy server to connect to the Internet.INTERNET_CONNECTION_PROXY = 4;// local system's modem is busy with a non-Internet connection.INTERNET_CONNECTION_MODEM_BUSY = 8;vardwConnectionTypes : DWORD;begindwConnectionTypes := INTERNET_CONNECTION_MODEM+ INTERNET_CONNECTION_LAN+ INTERNET_CONNECTION_PROXY;Result := InternetGetConnectedState(@dwConnectionTypes, 0);end;
    //函数结束
    procedure Tfrm_login.FormShow(Sender: TObject);
    var
    name,pwd:string;
    flag:boolean;
    begin
         AssignFile( RecFile, 'MYREC.FIL' ) ;
         Reset( RecFile ) ;
         read( RecFile, MyRec) ;
         CloseFile( RecFile ) ;
         name :=MyRec.Name;
         pwd :=MyRec.Condition;
         flag:=false;
         if (name='123') and (pwd='123') then
         flag:=true
         else
         flag:=false;
      //
      Application.Initialize;
      frm_login := Tfrm_login.Create(application);
      frm_login.Show;
      frm_login.Update;
      if InternetConnected and flag then  {满足条件,运行a窗体}
        Application.CreateForm(Tfrm_main, frm_main)
      else                                {不满足条件,运行b窗体}
        Application.CreateForm(Tfrm_myfirst, frm_myfirst);
      frm_login.Hide;
      frm_login.Free;
      Application.Run;
       //
    end;
    end.