我写了一个过程:如下
Procedure TTM_Login.OPen_SYS;
var
Tempstr:string;
begin
with DataModule1 do
begin
if M_Connection.Connected=false then
begin
Tempstr:='';
Tempstr:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID='
+ User_UserName + ';Initial Catalog=' +
User_ServerData + ';Data Source=' +
User_ServerName;
{edit1.Text:=Tempstr;}
M_Connection.ConnectionString:=Tempstr;
M_Connection.Open();
end;
end;if DataModule1.M_Connection.Connected=true then
Tempstr:='';
Tempstr:='select UserName from UserLogin where UserName = ' +
'''' + edit1.Text + '''' + 'and UserPass = ' + ''''
+ edit2.Text + '''';
DataModule1.M_Query.SQL.Text:= Tempstr;
DataModule1.M_Query.Open;
if DataModule1.M_Query.Recordset.RecordCount>0 then
begin
TM_Form.Show;
TM_Login.Hide;
end
else
begin
showmessage('用户名或密码错误,请重新输入。');
end;
DataModule1.M_Query.Free;
end;然后运行过程:
OPen_SYS;当程序第一次运行的时候,OPen_SYS可以运行,没有错误,但是当第二次在运行的时候,就报错,说什么错误挂起'FFFFFF'之类。请大侠们帮忙看看。谢谢。
Procedure TTM_Login.OPen_SYS;
var
Tempstr:string;
begin
with DataModule1 do
begin
if M_Connection.Connected=false then
begin
Tempstr:='';
Tempstr:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID='
+ User_UserName + ';Initial Catalog=' +
User_ServerData + ';Data Source=' +
User_ServerName;
{edit1.Text:=Tempstr;}
M_Connection.ConnectionString:=Tempstr;
M_Connection.Open();
end;
end;if DataModule1.M_Connection.Connected=true then
Tempstr:='';
Tempstr:='select UserName from UserLogin where UserName = ' +
'''' + edit1.Text + '''' + 'and UserPass = ' + ''''
+ edit2.Text + '''';
DataModule1.M_Query.SQL.Text:= Tempstr;
DataModule1.M_Query.Open;
if DataModule1.M_Query.Recordset.RecordCount>0 then
begin
TM_Form.Show;
TM_Login.Hide;
end
else
begin
showmessage('用户名或密码错误,请重新输入。');
end;
DataModule1.M_Query.Free;
end;然后运行过程:
OPen_SYS;当程序第一次运行的时候,OPen_SYS可以运行,没有错误,但是当第二次在运行的时候,就报错,说什么错误挂起'FFFFFF'之类。请大侠们帮忙看看。谢谢。
Tempstr:='';//????????????????
这后面的不要
因为第一次把它free了,所以第二次运行时找不到DataModule1.M_Query,
当然报错!