unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, DB, DBTables;type
TForm2 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
Button2: TButton;
Image1: TImage;
Query1: TQuery;
DataSource1: TDataSource;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const
ScreenWidth=1024;
ScreenHeight=768;var
Form2: TForm2;implementation
uses Unit1;{$R *.dfm}procedure TForm2.Button2Click(Sender: TObject);
begin
close;
end;procedure TForm2.Button1Click(Sender: TObject);
begin
with query1 do
begin
close;
parambyname('mc').AsString:=Edit1.Text;
parambyname('mm').AsString:=Edit2.Text;
open;
end;
if query1.recordcount<>0 then
begin
form1.Show;
form1.StatusBar1.Panels[1].Text :=query1.FieldByName('RY0102').AsString;
end
else
begin
application.MessageBox('您的用户名或密码不正确,请重新输入!','提示',mb_ok);
edit1.SetFocus;
abort;
end;
end;procedure TForm2.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
edit2.SetFocus;
end;procedure TForm2.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
Button1.SetFocus;
end;procedure TForm2.FormShow(Sender: TObject);
begin
edit1.SetFocus;
end;procedure TForm2.FormCreate(Sender: TObject);
begin
inherited;
Font.Name := '宋体';
Font.Size := 9;
Scaled := True;
if (screen.Width<>ScreenWidth) then
begin
Height := LongInt(height)*longInt(Screen.height)div ScreenHeight;
Width := LongInt(Width)*LongInt(screen.width)div ScreenWidth;
ScaleBy(Screen.width,ScreenWidth);
end;
end;
end.
-----------------------------------------------------------------------------
本程序form2为登录界面,想请教各位一个问题,form2界面在登陆到form1界面后form1界面关闭,我在form1.StatusBar1.Panels[1].Text :=query1.FieldByName('RY0102').AsString;后添加form2.close;但是连form1都不能显示了!!!我该怎么将登录界面form2关闭呢???请高手门指点!!!谢谢!!!
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, DB, DBTables;type
TForm2 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
Button2: TButton;
Image1: TImage;
Query1: TQuery;
DataSource1: TDataSource;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const
ScreenWidth=1024;
ScreenHeight=768;var
Form2: TForm2;implementation
uses Unit1;{$R *.dfm}procedure TForm2.Button2Click(Sender: TObject);
begin
close;
end;procedure TForm2.Button1Click(Sender: TObject);
begin
with query1 do
begin
close;
parambyname('mc').AsString:=Edit1.Text;
parambyname('mm').AsString:=Edit2.Text;
open;
end;
if query1.recordcount<>0 then
begin
form1.Show;
form1.StatusBar1.Panels[1].Text :=query1.FieldByName('RY0102').AsString;
end
else
begin
application.MessageBox('您的用户名或密码不正确,请重新输入!','提示',mb_ok);
edit1.SetFocus;
abort;
end;
end;procedure TForm2.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
edit2.SetFocus;
end;procedure TForm2.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
Button1.SetFocus;
end;procedure TForm2.FormShow(Sender: TObject);
begin
edit1.SetFocus;
end;procedure TForm2.FormCreate(Sender: TObject);
begin
inherited;
Font.Name := '宋体';
Font.Size := 9;
Scaled := True;
if (screen.Width<>ScreenWidth) then
begin
Height := LongInt(height)*longInt(Screen.height)div ScreenHeight;
Width := LongInt(Width)*LongInt(screen.width)div ScreenWidth;
ScaleBy(Screen.width,ScreenWidth);
end;
end;
end.
-----------------------------------------------------------------------------
本程序form2为登录界面,想请教各位一个问题,form2界面在登陆到form1界面后form1界面关闭,我在form1.StatusBar1.Panels[1].Text :=query1.FieldByName('RY0102').AsString;后添加form2.close;但是连form1都不能显示了!!!我该怎么将登录界面form2关闭呢???请高手门指点!!!谢谢!!!
begin
form1.Show;
form1.StatusBar1.Panels[1].Text :=query1.FieldByName('RY0102').AsString;
close;
end
else
begin
application.MessageBox('您的用户名或密码不正确,请重新输入!','提示',mb_ok);
edit1.SetFocus;
abort;
end;
end;这样不就行了?
如果你改变登录界面实现方式,那么估计只能把,登录窗体hide掉了,然后在你的主界面退出的时候把登录窗体一起close掉。
当然你可以改变登录的实现方式,比若吧登录窗体显示写在主界面的formshow里,或者写在程序文件里Application.Run;之前,主窗体create之后,这样就没问题了
begin
FrmLog:=TFrmLog.Create(self);
FrmLog.ShowModal;
end;在登录窗体确定按钮的click事件中
if 用户名和密码正确 then
begin
Ischenggong:=True; //用来检测是否登录成功,默认为False
FrmLog.Close ; //如果时.hide,登录窗口没有关闭,最后退出整个程序时
可能留有进程在任务管理器
FrmMain.Show;
end
在登录窗体取消按钮的click事件中 application.Terminateprocedure TFrmLog.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if not Ischenggong then application.Terminate;
end;如果没有最后这段代码,那么当你点登录窗体右上角‘×’时,也会到达主界面。