J
jihaiming
Unregistered / Unconfirmed
GUEST, unregistred user!
unit login;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Mask, ExtCtrls, DB, Grids, DBGrids, Contnrs,
DBClient, ComCtrls;
type
TForm1 = class(TForm)
edtName: TLabeledEdit;
edtPassword: TMaskEdit;
Label1: TLabel;
ClientDataSet1: TClientDataSet;
ClientDataSet1aotuID: TAutoIncField;
ClientDataSet1ID: TWideStringField;
ClientDataSet1NAME: TWideStringField;
ClientDataSet1SEX: TWideStringField;
ClientDataSet1JOB: TWideStringField;
ClientDataSet1TEL: TWideStringField;
ClientDataSet1CALL: TWideStringField;
ClientDataSet1DEP: TWideStringField;
ClientDataSet1GROUP_ID: TWideStringField;
ClientDataSet1PASSWORD: TWideStringField;
DataSource1: TDataSource;
btnLogin: TButton;
DBGrid1: TDBGrid;
btnHint: TButton;
StatusBar1: TStatusBar;
procedure FormCreate(Sender: TObject);
procedure btnLoginClick(Sender: TObject);
procedure btnHintClick(Sender: TObject);
private
ProfileList: TObjectList;
public
{ Public declarations }
end;
TProfile = class(TObject)
Name : String;
Dep : String;
Password :String;
Job : String;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
AMan:TProfile;
begin
DBGrid1.Visible:=false;
self.Width:=310;
ClientDataSet1.LoadFromFile('login.dat');
ClientDataSet1.Active:=True;
ProfileList:=TObjectList.Create(True);
for i:=1 to ClientDataSet1.RecordCount do
begin
AMan:=TProfile.Create;
AMan.Name:=ClientDataSet1.FieldByName('Name').AsString;
AMan.Job:=ClientDataSet1.FieldByName('Job').AsString;
AMan.Dep:=ClientDataSet1.FieldByName('Dep').AsString;
AMan.Password :=ClientDataSet1.FieldByName('Password').AsString;
ProfileList.Add(AMan);
ClientDataSet1.Next;
end;
end;
procedure TForm1.btnLoginClick(Sender: TObject);
var
i:integer;
AMan:TProfile;
begin
for i :=0 to (ProfileList.Count-1) do
begin
AMan:=TProfile(ProfileList.Items);
if (Trim(AMan.Name)=Trim(edtName.Text)) and
(Trim(AMan.Password)=Trim(edtPassword.Text)) then
begin
application.MessageBox('登录成功。','提示',MB_OK+MB_ICONINFORMATION);
StatusBar1.Panels[0].Text:='当前用户:'+AMan.Name+AMan.Dep+AMan.Job;
exit;
end;
end;
application.MessageBox('非法用户,登录失败!','提示',MB_OK+MB_ICONSTOP);
end;
procedure TForm1.btnHintClick(Sender: TObject);
begin
if DBGrid1.Visible then
begin
self.Width:=310;
btnHint.Caption:='>>';
end
else
begin
self.Width:=713;
btnHint.Caption:='<<'
end;
DBGrid1.Visible:=not DBGrid1.Visible;
end;
end.
请问在上面的程序中,AMan对象创建后,是不是应该手动销毁呢? 好像它没有属主啊.
高手指点. 新人~
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Mask, ExtCtrls, DB, Grids, DBGrids, Contnrs,
DBClient, ComCtrls;
type
TForm1 = class(TForm)
edtName: TLabeledEdit;
edtPassword: TMaskEdit;
Label1: TLabel;
ClientDataSet1: TClientDataSet;
ClientDataSet1aotuID: TAutoIncField;
ClientDataSet1ID: TWideStringField;
ClientDataSet1NAME: TWideStringField;
ClientDataSet1SEX: TWideStringField;
ClientDataSet1JOB: TWideStringField;
ClientDataSet1TEL: TWideStringField;
ClientDataSet1CALL: TWideStringField;
ClientDataSet1DEP: TWideStringField;
ClientDataSet1GROUP_ID: TWideStringField;
ClientDataSet1PASSWORD: TWideStringField;
DataSource1: TDataSource;
btnLogin: TButton;
DBGrid1: TDBGrid;
btnHint: TButton;
StatusBar1: TStatusBar;
procedure FormCreate(Sender: TObject);
procedure btnLoginClick(Sender: TObject);
procedure btnHintClick(Sender: TObject);
private
ProfileList: TObjectList;
public
{ Public declarations }
end;
TProfile = class(TObject)
Name : String;
Dep : String;
Password :String;
Job : String;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
AMan:TProfile;
begin
DBGrid1.Visible:=false;
self.Width:=310;
ClientDataSet1.LoadFromFile('login.dat');
ClientDataSet1.Active:=True;
ProfileList:=TObjectList.Create(True);
for i:=1 to ClientDataSet1.RecordCount do
begin
AMan:=TProfile.Create;
AMan.Name:=ClientDataSet1.FieldByName('Name').AsString;
AMan.Job:=ClientDataSet1.FieldByName('Job').AsString;
AMan.Dep:=ClientDataSet1.FieldByName('Dep').AsString;
AMan.Password :=ClientDataSet1.FieldByName('Password').AsString;
ProfileList.Add(AMan);
ClientDataSet1.Next;
end;
end;
procedure TForm1.btnLoginClick(Sender: TObject);
var
i:integer;
AMan:TProfile;
begin
for i :=0 to (ProfileList.Count-1) do
begin
AMan:=TProfile(ProfileList.Items);
if (Trim(AMan.Name)=Trim(edtName.Text)) and
(Trim(AMan.Password)=Trim(edtPassword.Text)) then
begin
application.MessageBox('登录成功。','提示',MB_OK+MB_ICONINFORMATION);
StatusBar1.Panels[0].Text:='当前用户:'+AMan.Name+AMan.Dep+AMan.Job;
exit;
end;
end;
application.MessageBox('非法用户,登录失败!','提示',MB_OK+MB_ICONSTOP);
end;
procedure TForm1.btnHintClick(Sender: TObject);
begin
if DBGrid1.Visible then
begin
self.Width:=310;
btnHint.Caption:='>>';
end
else
begin
self.Width:=713;
btnHint.Caption:='<<'
end;
DBGrid1.Visible:=not DBGrid1.Visible;
end;
end.
请问在上面的程序中,AMan对象创建后,是不是应该手动销毁呢? 好像它没有属主啊.
高手指点. 新人~