刚学delphi,大家帮帮我啊
login是一个登录窗体,connectform是一个连接数据库窗体,程序启动时检测注册表中有无键值,如无,则弹出connectform连接数据库并写连接字符串到注册表,如有,则用来此键值的值连接sqlserver。当注册表无键时,已经测试成功,有健时,能连接成功,但为何connectform还是显示出来,我明明已经hide了啊!
procedure Tlogin.FormCreate(Sender: TObject);
begin
   reg:=TRegistry.create;
   try
    //注册根键
      reg.RootKey:=HKEY_CURRENT_USER;
      //检测是否存在建
      if (reg.OpenKey('Software\jinxi\sqlserver',False))=false then
           begin
           //直接创建并显示数据库连接窗体
            Application.CreateForm(Tconnectform, connectform);
            connectform.ShowModal;
           end
      else
      //if (reg.OpenKey('Software\jinxi\sqlserver',true))=true then
        begin
          reg.ReadString('connectstring');
          //要引用另一窗体中的组件,必须先创建该窗体
          Application.CreateForm(Tconnectform, connectform);
          connectform.Hide;
          connectstr:=reg.ReadString('connectstring');
          //loginuser.Text:=connectform.serverlink.ConnectionString;
          connectform.serverlink.ConnectionString:=connectstr;
          connectform.serverlink.Connected:=true;
          
        end;
   finally
    showmessage(connectstr);
   end;
end;

解决方案 »

  1.   

    首先指出,楼主openkey  后没 close,这是比较不好的习惯,
    我试了一下,确实是那样,
    我用Tconnectform.Create(self).show;
    gz
      

  2.   

    不行啊,我是把工程文件中的Application.CreateForm(Tconnectform, connectform);移动到了上面的程序中的。按照你的做法把Application.CreateForm(Tconnectform, connectform);替换成Tconnectform.Create(self).show,到else后就出错了。产生错误的原因是什么啊,上面的程序应该如何修改?
    急!帮帮忙啊
      

  3.   

    connectform 不要在工程文件中创建吧!
    从object->option->form
      

  4.   

    总算试验出来了,Application.CreateForm(Tconnectform, connectform);是由程序自动创建的窗体,不能隐藏的,只能用 connectform:=Tconnectform.create(application);