我在主窗体定义一变量A
var
a:string;
mainfrm: Tmainfrm;然后在登陆窗体 登陆时把登陆ID 给A登陆事件
var s:string;
begin
if idtext.Text ='' then
begin
Application.MessageBox('帐号不能为空', '错误', MB_OK + MB_ICONSTOP);
idtext.SetFocus;
Exit;
end;
if pswedit.Text ='' then
begin
Application.MessageBox('密码不能为空','错误',MB_OK+mb_iconstop);
pswedit.SetFocus;
exit;
end;
with DataModule1.qrylog do
begin
Close;
SQL.Clear;
s:='select * from login where 1=1';
s:=s+'and id=:id and psw=:password';
SQL.Add(s);
Parameters.ParamByName('id').Value :=Trim(idtext.Text);
Parameters.ParamByName('password').Value :=Trim(pswedit.Text); Open;
if RecordCount =0 then
begin
Application.MessageBox('密码或用户名有错', '错误', MB_OK + MB_ICONSTOP);
idtext.Text :='';
pswedit.Text :='';
idtext.SetFocus;
end
else
begin
DataModule1.qryloginlog.close;
DataModule1.qryloginlog.SQL.Clear;
DataModule1.qryloginlog.SQL.Add('insert into loginlog values('''+idtext.Text+''','''+StatusBar1.Panels[1].Text+''')');
DataModule1.qryloginlog.ExecSQL;
DataModule1.qryloginlog.Free;
a:=idtext.Text;
if FieldByName('purview').AsInteger =1 then
begin
mainfrm.Label1.Caption :='管理员';
end;
if FieldByName('purview').AsInteger =0 then
begin
mainfrm.useredit.Text :=a;
end;
Free;
mainfrm.Show;
log.Close;
end; end;
主窗体 有个EDIT 引用了这个啊
可是当一登陆 进入主窗体就提示 未知 错误 是怎么搞的啊
这个a通过showmessage 在主窗体中用 不会有错误
但是要是把a的值 给了别的 控件 就错
var
a:string;
mainfrm: Tmainfrm;然后在登陆窗体 登陆时把登陆ID 给A登陆事件
var s:string;
begin
if idtext.Text ='' then
begin
Application.MessageBox('帐号不能为空', '错误', MB_OK + MB_ICONSTOP);
idtext.SetFocus;
Exit;
end;
if pswedit.Text ='' then
begin
Application.MessageBox('密码不能为空','错误',MB_OK+mb_iconstop);
pswedit.SetFocus;
exit;
end;
with DataModule1.qrylog do
begin
Close;
SQL.Clear;
s:='select * from login where 1=1';
s:=s+'and id=:id and psw=:password';
SQL.Add(s);
Parameters.ParamByName('id').Value :=Trim(idtext.Text);
Parameters.ParamByName('password').Value :=Trim(pswedit.Text); Open;
if RecordCount =0 then
begin
Application.MessageBox('密码或用户名有错', '错误', MB_OK + MB_ICONSTOP);
idtext.Text :='';
pswedit.Text :='';
idtext.SetFocus;
end
else
begin
DataModule1.qryloginlog.close;
DataModule1.qryloginlog.SQL.Clear;
DataModule1.qryloginlog.SQL.Add('insert into loginlog values('''+idtext.Text+''','''+StatusBar1.Panels[1].Text+''')');
DataModule1.qryloginlog.ExecSQL;
DataModule1.qryloginlog.Free;
a:=idtext.Text;
if FieldByName('purview').AsInteger =1 then
begin
mainfrm.Label1.Caption :='管理员';
end;
if FieldByName('purview').AsInteger =0 then
begin
mainfrm.useredit.Text :=a;
end;
Free;
mainfrm.Show;
log.Close;
end; end;
主窗体 有个EDIT 引用了这个啊
可是当一登陆 进入主窗体就提示 未知 错误 是怎么搞的啊
这个a通过showmessage 在主窗体中用 不会有错误
但是要是把a的值 给了别的 控件 就错
begin if log =nil then
log :=tlog.create(nil);
log.ShowModal;
if log.ModalResult =mrok then
begin
application.Terminate;
end;
if Label1.Caption <>'管理员' then
begin
useredit.Text:=a;
end;
birthday.Date :=Date;
tbtime.Date :=Date;
khnameedit.SetFocus;
with DataModule1.qrycustom do
begin
Close;
SQL.Clear;
if useredit.Text ='' then
SQL.Add('select * from customlog')
else
SQL.Add('select write from customlog where write='+ 'useredit.text');
Open;
end;
end;
这里 谢谢了
Application.Run上面的代码是什么?
begin
Application.Initialize;
Application.CreateForm(TDataModule1, DataModule1); //《〈,,
Application.CreateForm(Tmainfrm, mainfrm);
//....
Application.Run;
end.
应该是 zswang 说的 问题
处出错明显说明是在窗体创建时发生的某个事件出错了!或是再某窗体创建时就掉用了尚未创建的窗体或类里的变量!