delphi运行时提示 with DM.Query do 出错,请各位大侠帮我看看,谢谢!
unitUnit1;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,F...
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB,ADODB,ExtCtrls;
type
TFrmLogin = class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
cbx1: TComboBox;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
pass:Boolean;
{ Private declarations }
public
{ Public declarations }
end;
var
FrmLogin: TFrmLogin;
implementation
uses Unit3,Unit2;
{$R *.dfm}
//----------------------------------------------------------------------------
procedure TFrmLogin.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if pass then
close
else
Application.Terminate;
end;
//----------------------------------------------------------------------------
procedure TFrmLogin.Button2Click(Sender: TObject);
begin
close;
end;
//---------------------------------------------------------------------------
procedure TFrmLogin.FormCreate(Sender: TObject);
begin
with DM.Query do //运行时这里报错。
begin
Close;
SQL.Clear;
SQL.Add('select * from User');
Open;
while not Eof do
begin
cbx1.Items.Add(Fieldbyname('username').AsString);
next;
end;
end;
end;
//----------------------------------------------------------------------------
procedure TFrmLogin.Button1Click(Sender: TObject);
begin
with DM.Query do //运行时这里报错。
begin
close;
SQL.Clear;
SQL.Add('select * from user where username=:UN and userpass=:UP') ;
Parameters.ParamByName('UN').Value := cbx1.Text ;
Parameters.ParamByName('UP').Value := edit2.Text ;
Open;
Frm_main.Show;
if recordCount<1 then
begin
showmessage('对不起!用户名或密码错误!');
Exit;
end;
pass:=true;
self.Close;
end;
end;
end.
这就是报错的问题,请各位大侠帮忙看看,小弟非常感谢。 展开
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB,ADODB,ExtCtrls;
type
TFrmLogin = class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
cbx1: TComboBox;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
pass:Boolean;
{ Private declarations }
public
{ Public declarations }
end;
var
FrmLogin: TFrmLogin;
implementation
uses Unit3,Unit2;
{$R *.dfm}
//----------------------------------------------------------------------------
procedure TFrmLogin.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if pass then
close
else
Application.Terminate;
end;
//----------------------------------------------------------------------------
procedure TFrmLogin.Button2Click(Sender: TObject);
begin
close;
end;
//---------------------------------------------------------------------------
procedure TFrmLogin.FormCreate(Sender: TObject);
begin
with DM.Query do //运行时这里报错。
begin
Close;
SQL.Clear;
SQL.Add('select * from User');
Open;
while not Eof do
begin
cbx1.Items.Add(Fieldbyname('username').AsString);
next;
end;
end;
end;
//----------------------------------------------------------------------------
procedure TFrmLogin.Button1Click(Sender: TObject);
begin
with DM.Query do //运行时这里报错。
begin
close;
SQL.Clear;
SQL.Add('select * from user where username=:UN and userpass=:UP') ;
Parameters.ParamByName('UN').Value := cbx1.Text ;
Parameters.ParamByName('UP').Value := edit2.Text ;
Open;
Frm_main.Show;
if recordCount<1 then
begin
showmessage('对不起!用户名或密码错误!');
Exit;
end;
pass:=true;
self.Close;
end;
end;
end.
这就是报错的问题,请各位大侠帮忙看看,小弟非常感谢。 展开
2个回答
展开全部
注意你的工程文件
program sfxtrj;
uses
Forms,
sfXT_mai in 'sfXT_mai.pas' {sf_mai},
U_sjmk in 'U_sjmk.pas' {fr_sjmk: TDataModule},
hzzpy in 'hzzpy.pas',
DESCrypt in 'DESCrypt.pas',
DBGrid2Excel in 'DBGrid2Excel.pas',
U_mai1 in 'U_mai1.pas' {fr_mai1},
qd in 'qd.pas' {qdck},
glyxkck in 'glyxkck.pas' {glyxk};
{$R *.res}
begin
Application.Initialize;
qdck:=Tqdck.Create(Application);
qdck.Show;
qdck.Update;
Application.CreateForm(Tsf_mai, sf_mai);//主窗体
Application.CreateForm(Tfr_sjmk, fr_sjmk);//数据模块(窗体)
Application.CreateForm(Tfr_mai1, fr_mai1);
Application.CreateForm(Tglyxk, glyxk);
qdck.Free;
Application.Run;
end.
以上工程文件运行时会出现和你的错误一样的错误
改一下 ,让数据模块先创建,然后再创建主窗体
Application.CreateForm(Tfr_sjmk, fr_sjmk);//数据模块(窗体)
Application.CreateForm(Tsf_mai, sf_mai);//主窗体
这样就不会出现你说那种出错了。
program sfxtrj;
uses
Forms,
sfXT_mai in 'sfXT_mai.pas' {sf_mai},
U_sjmk in 'U_sjmk.pas' {fr_sjmk: TDataModule},
hzzpy in 'hzzpy.pas',
DESCrypt in 'DESCrypt.pas',
DBGrid2Excel in 'DBGrid2Excel.pas',
U_mai1 in 'U_mai1.pas' {fr_mai1},
qd in 'qd.pas' {qdck},
glyxkck in 'glyxkck.pas' {glyxk};
{$R *.res}
begin
Application.Initialize;
qdck:=Tqdck.Create(Application);
qdck.Show;
qdck.Update;
Application.CreateForm(Tsf_mai, sf_mai);//主窗体
Application.CreateForm(Tfr_sjmk, fr_sjmk);//数据模块(窗体)
Application.CreateForm(Tfr_mai1, fr_mai1);
Application.CreateForm(Tglyxk, glyxk);
qdck.Free;
Application.Run;
end.
以上工程文件运行时会出现和你的错误一样的错误
改一下 ,让数据模块先创建,然后再创建主窗体
Application.CreateForm(Tfr_sjmk, fr_sjmk);//数据模块(窗体)
Application.CreateForm(Tsf_mai, sf_mai);//主窗体
这样就不会出现你说那种出错了。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询