with query1 do
begin
close;
sql.clear;
sql.add('select 用户名,用户类型,密码 from 用户表1');
sql.add('where 用户名=:usename');
sql.add('and 密码=:password');
parambyname('usename').Asstring:=edit1.text;
parambyname('password').AsString:=edit2.Text;
prepare;
open;
name := edit1.Text;
usertype := FieldByName('用户类型').value; // 在这里赋值
end;
begin
close;
sql.clear;
sql.add('select 用户名,用户类型,密码 from 用户表1');
sql.add('where 用户名=:usename');
sql.add('and 密码=:password');
parambyname('usename').Asstring:=edit1.text;
parambyname('password').AsString:=edit2.Text;
prepare;
open;
name := edit1.Text;
usertype := FieldByName('用户类型').value; // 在这里赋值
end;
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Db, DBTables, Grids, DBGrids, ADODB;type
TForm_Entry = class(TForm)
Button1: TButton;
Button2: TButton;
Label1: TLabel;
Label2: TLabel;
Edit_Identity: TEdit;
Edit_Cipher: TEdit;
DataSource_Entry: TDataSource;
Table_Entry: TTable;
Database_Entry: TDatabase;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form_Entry: TForm_Entry;
Frequency_Entry:Integer=0;implementationuses Unit2;
var hnd: THandle; //防止程序被二次运行procedure TForm_Entry.FormShow(Sender: TObject);
begin
Table_Entry.Filter :='[Teacher/Student]='+''''+'管理员'+'''';
Table_Entry.Filtered :=true;
//Edit_Identity.Text:=Table_Entry.FieldByName('Teacher/student').AsString;
end;procedure TForm_Entry.Button1Click(Sender: TObject);
begin
If (Edit_Identity.Text=Table_Entry.FieldByName('Name').AsString) and (Edit_Cipher.Text=Table_Entry.FieldByName('Cipher').AsString) then
begin
Form_major.show ;
Form_Entry.Hide ;
end
else
begin
Showmessage('用户名或密码错误,请确定后重试');
Frequency_Entry:=Frequency_Entry+1;
Edit_Identity.Clear ;
Edit_Cipher.Clear ;
end ;
If Frequency_Entry=3 then
begin
showmessage('登录错误!本系统即将退出,请确定用户名和密码后重新登录!');
Form_Entry.Close ;
endend;initialization //防止程序被二次运行
hnd := CreateMutex(nil, True, 'irgendwaseinmaliges');
if GetLastError = ERROR_ALREADY_EXISTS then Halt;finalization //防止程序被二次运行
if hnd <> 0 then CloseHandle(hnd);{$R *.DFM}end.
name := edit1.Text;
usertype := FieldByName('用户类型').value;出错
出错内容为
access violation at address 004ac0d8 in moudle 'project.exe' read of address 00000000