标题:delphi 登陆界面后显示主窗体,出现 access violation 错误
取消只看楼主
a373492883
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2014-2-28
结帖率:0
 问题点数:0 回复次数:1 
delphi 登陆界面后显示主窗体,出现 access violation 错误
delphi先是登陆窗体,用户名密码正确后显示主窗体,程序如下,目前错误,登陆界面运行后,出现access violation at address错误,求解哪错了。。。哎,憋了我2天了。。那是相当难受


unit Unit20141126_2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, ADODB;

type
  TForm2 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;


implementation

uses Unit20141126_2_2;

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
var
   name,password,sqlstr:string;
begin
        if (length(trim(edit1.Text))>0) or (length(trim(edit2.Text))>0) then
        begin
              name:=trim(edit1.Text); //取得用户输入的用户名
              password:=trim(edit2.Text); //取得用户输入的密码
               sqlstr:='select * from t_user where (username='''+name+''') and(userpass='''+password+''')';
               with Tadoquery.create(nil) do
               try
                     connection:=form1.adoconnection1;
                     close;
                     sql.clear;
                     sql.add(sqlstr);
                     open;
                          if recordcount>0 then
                          begin
                               form2.hide;
                               showmessage('登陆成功');
                               Application.createForm(TForm1,Form1);
                               Form1.ShowModal;

                          end
                          else
                          begin
                               showmessage('用户名密码错误');
                               edit1.SetFocus;
                               edit1.SelectAll;
                          end;

               finally
                       free;
               end;

        end
        else
        begin
               showmessage('请输入用户名密码');
               edit1.SelectAll;
        end;
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
close;
end;

end.
搜索更多相关主题的帖子: Windows address access 用户名 
2014-11-27 16:57
a373492883
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2014-2-28
得分:0 
好吧我承认我不是变成的材料。。。。
2015-02-25 09:31



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-439258-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026397 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved