我在主窗体定义一变量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的值 给了别的 控件 就错

解决方案 »

  1.   

    procedure Tmainfrm.FormCreate(Sender: TObject);
    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;
    这里  谢谢了
      

  2.   

    未知错误就报告这个又报告这里错误  Application.Run;
      

  3.   

    报未知错误,应该不是在这里报错的
    Application.Run上面的代码是什么?
      

  4.   

    //到工程文件中,将DataModule1创建代码提前
    begin
      Application.Initialize;
      Application.CreateForm(TDataModule1, DataModule1); //《〈,,
      Application.CreateForm(Tmainfrm, mainfrm);
    //....
      Application.Run;
    end.
      

  5.   

    把A:string写到类里面public:后面,调用试试,我经常这么做,另外要注意赋初值
      

  6.   

    工程项目上点右键调整下窗体顺序。
    应该是 zswang 说的 问题
      

  7.   

    就是通过了又怎么样?这样的程序结构简直有辱DELPHI。怪不得DELPHI老遭人抨击,就是你们这样的用DELPHI高开发的人太多了,把DELPHI的名声都搞坏了
      

  8.   

    楼上的真恶心说了这么长时间你们也没找到错误其实是access数据库 的write是保留字段 不能使用郁闷死
      

  9.   

    Application.Run
    处出错明显说明是在窗体创建时发生的某个事件出错了!或是再某窗体创建时就掉用了尚未创建的窗体或类里的变量!