delphi 中,主界面为什么出不来?

来源:百度知道 编辑:UC知道 时间:2024/06/03 22:07:40
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Unit2;

type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
edtName: TEdit;
edtPass: TEdit;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
if (edtName.Text='1')and(edtPass.Text='1') then begin

Form1.Close;
Form2.Show;

end

else
showmessage('姓名戓密码错。');

end;

procedure TForm1.Button2Click(Sender: TO

lz想做登陆页面的吧..

我估计lz设计的是Form2是项目的主窗体,就是登陆页面,
但是实际中form1是最终程序的主界面展示..

if (edtName.Text='1')and(edtPass.Text='1') then begin

Form1.Close; //这句话执行,整个程序已经退出了. 建议改成Form1.hide;记的最后form2中退出的时候记得再把Form1.close()
Form2.Show;

end

程序一开始进行的这些操作建议在工程文件里改
以下是类似代码:
program client;

uses
Forms,
U_client in 'U_client.pas' {Form1},
U_about in 'U_about.pas' {AboutBox};

{$R *.res}

begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TAboutBox, AboutBox);
Application.Run;
end.

本例中 如果样想程序运行就显示AboutBox
那么改成
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TAboutBox, AboutBox);
application.ShowMainForm :=false;//启动时主窗体不显示,并且不会闪烁
AboutBox.show;//显示这个窗口
Application.Run;

在AboutBox要显示主