...
implementation
uses dm,main;
...
新建一个datamodule,其name属性为data,保存为dm.pas;
quser为adoquery组件,cc为adoconnetion组件
均位data的数据窗体里我在做login窗体时
procedure Ttlogin.BitBtn1Click(Sender: TObject);
begin
ttime := ttime + 1;
if ttime>=4 then
    begin
      Application.MessageBox('非法用户,系统将退出!', '提示', Mb_Ok or Mb_IconStop);
      Application.Terminate;
    end; try
 with dm.data do
  begin
  quser.close;
  quser.SQL.Clear;
  quser.SQL.Add('select * from tuser where id='''+edit1.text+'''');
  cc.Connected:=true;
  quser.Open;
  end
  except
  begin
  Application.MessageBox('连接数据库出错,请写系统管理员联系!', '提示', Mb_Ok or Mb_IconStop);
  close;
  end
  end;  if dm.data.quser.RecordCount=1 then
   if dm.data.quser['pwd']=edit2.Text then
    begin
    flag:=true;
    tmain.ShowModal;
    tlogin.Free;
    end
   else begin
    flag:=false;
    Application.MessageBox('密码错误!', '提示', Mb_Ok or Mb_IconStop);
    end
   else begin
   flag:=false;
   Application.MessageBox('用户名错误!', '提示', Mb_Ok or Mb_IconStop);
   end;
   close;
   end;
中程序运行到 with dm.data do 这里就出错了,不知道哪儿有问题?!

解决方案 »

  1.   

    什么错误也不说...你的dm窗口是不是比logon窗口后创建啊...
      

  2.   

    是不是缺这句:
    Application.CreateForm(TDM, DM);
      

  3.   

    对应该是
    Application.CreateForm(TDM,DM);
    这句需要先创建登录窗体后创建
      

  4.   

    adoconnection,adoquery等控件里的active属性均为false;
    如何在form1里面初始化它们?
    oncreate事件里添加么?datamodule1存为dm.pas,name属性为data
    adoconnection1的name为cc
    adoquery1的name为qdj
    dataset1的name为dsdj现有form1窗体,
    ...
    implementation
    uses dm;
    ...dbgrid的datasource为data.dsdj;
    现在需要一打开form1时,在dbgrid里就可以显示出select * from tdj里的内容出来我在form1的oncreate事件里加入
    data.qdj.active:=true;
    时,就会出错。