我是把别的程序里的模块引用再我的程序中出现的问题,原码如下:unit uMgrUserF;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, ExtCtrls, dbtables;
type
TMgrUserF = class(TFrame)
Button1: TButton;
Panel1: TPanel;
GroupBox1: TGroupBox;
ListView1: TListView;
GroupBox2: TGroupBox;
GroupBox3: TGroupBox;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
Button2: TButton;
GroupBox4: TGroupBox;
Edit1: TEdit;
Edit2: TEdit;
Button3: TButton;
StaticText1: TStaticText;
StaticText2: TStaticText;
ComboBox1: TComboBox;
StaticText3: TStaticText;
Panel2: TPanel;
StaticText4: TStaticText;
procedure Button1Click(Sender: TObject);
procedure RadioButton1Click(Sender: TObject);
procedure RadioButton2Click(Sender: TObject);
procedure ListView1Change(Sender: TObject; Item: TListItem;
Change: TItemChange);
procedure ListView1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure RefreshUser;
function GetUserPwd(UserName : string):string;
function CheckExistUserName(UserName : string):boolean;
procedure InsUser(UserName,UserPwd:string;Power : integer);
procedure UpdateUser(UserName,UserPwd:string;Power : integer);
procedure DelUser(UserName : string);
constructor Create(AOwner : TComponent);override;
end;
var
MgrUserF : TMgrUserF;
implementation
uses uMainF,uGloabVar;
{$R *.DFM}
procedure TMgrUserF.Button1Click(Sender: TObject);
begin
Parent := nil;
MainF.Caption := '图书管理系统';
end;
constructor TMgrUserF.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
try
RefreshUser;
except
ListView1.Items.Clear;
MessageDlg('得到用户信息出错',mtError,[mbok],0);
end;
ComboBox1.ItemIndex := 2;
end;
procedure TMgrUserF.RefreshUser;
var
Query : TQuery;
begin
Query := TQuery.Create(nil);
Query.DatabaseName := DBName;
Query.SQL.Add('select * from tsyhb order by Class ');
Query.Open;
ListView1.Items.Clear;
while not Query.Eof do
begin
with ListView1.Items.Add do
begin
Caption := Query.FieldByName('UserName').AsString;
SubItems.Add(Query.FieldByName('Class').AsString);
end;
Query.Next;
end;
Query.Close;
Query.Free;
end;
procedure TMgrUserF.RadioButton1Click(Sender: TObject);
begin
Edit1.Enabled := True;
Edit1.Color := clWindow;
end;
procedure TMgrUserF.RadioButton2Click(Sender: TObject);
begin
Edit1.Enabled := False;
Edit1.Color := clBtnFace;
end;
function TMgrUserF.GetUserPwd(UserName: string): string;
var
Query : TQuery;
begin
try
Query := TQuery.Create(nil);
Query.DatabaseName := DBName;
Query.SQL.Add('select UserPwd from tsyhb where UserName =:UserName');
Query.ParamByName('UserName').AsString := UserName;
Query.Open;
Result := Query.FieldByName('UserPwd').AsString;
Query.Close;
Query.Free;
except
Result := '';
end;
end;
procedure TMgrUserF.ListView1Change(Sender: TObject; Item: TListItem;
Change: TItemChange);
begin
if ListView1.Selected <> nil then
begin
Edit1.Text := ListView1.Selected.Caption;
Edit2.Text := GetUserPwd(Edit1.Text);
ComboBox1.ItemIndex := StrToInt(ListView1.Selected.SubItems.Strings[0]);
end;
end;
procedure TMgrUserF.ListView1Click(Sender: TObject);
begin
if ListView1.Selected <> nil then
begin
Edit1.Text := ListView1.Selected.Caption;
Edit2.Text := GetUserPwd(Edit1.Text);
ComboBox1.ItemIndex := StrToInt(ListView1.Selected.SubItems.Strings[0]);
end;
end;
function TMgrUserF.CheckExistUserName(UserName: string): boolean;
var
Query : TQuery;
begin
try
Query := TQuery.Create(nil);
Query.DatabaseName := DBName;
Query.SQL.Add('select UserName from tsyhb where UserName =:UserName');
Query.ParamByName('UserName').AsString := UserName;
Query.Open;
Result := Query.RecordCount >0;
Query.Close;
Query.Free;
except
Result := False;
end;
end;
procedure TMgrUserF.DelUser(UserName: string);
var
Query : TQuery;
begin
Query := TQuery.Create(nil);
Query.DatabaseName := DBName;
Query.SQL.Add('delete from tsyhb where UserName =:UserName');
Query.ParamByName('UserName').AsString := UserName;
Query.ExecSQL;
Query.Free;
end;
procedure TMgrUserF.InsUser(UserName, UserPwd: string; Power: integer);
var
Query : TQuery;
begin
Query := TQuery.Create(nil);
Query.DatabaseName := DBName;
Query.SQL.Add('insert into tsyhb(UserName,UserPwd,Class) '+
'values
UserName,:UserPwd,:Class)');
Query.ParamByName('UserName').AsString := UserName;
Query.ParamByName('UserPwd').AsString := UserPwd;
Query.ParamByName('Class').AsInteger:= Power;
Query.ExecSQL;
Query.Free;
end;
procedure TMgrUserF.UpdateUser(UserName, UserPwd: string; Power: integer);
var
Query : TQuery;
begin
Query := TQuery.Create(nil);
Query.DatabaseName := DBName;
Query.SQL.Add('update tsyhb set UserPwd=:UserPwd,Class=:Class'+
' where UserName=:UserName');
Query.ParamByName('UserName').AsString := UserName;
Query.ParamByName('UserPwd').AsString := UserPwd;
Query.ParamByName('Class').AsInteger:= Power;
Query.ExecSQL;
Query.Free;
end;
procedure TMgrUserF.Button3Click(Sender: TObject);
begin
if RadioButton1.Checked then
begin
if CheckExistUserName(Edit1.Text) then
begin
MessageDlg('此用户已经存在',mtError,[mbok],0);
Exit;
end;
try
InsUser(Edit1.Text,Edit2.Text,ComboBox1.ItemIndex);
except
MessageDlg('新建用户出错',mtError,[mbok],0);
Exit;
end;
end;
if RadioButton2.Checked then
begin
try
UpdateUser(Edit1.Text,Edit2.Text,ComboBox1.ItemIndex);
except
MessageDlg('修改用户出错',mtError,[mbok],0);
Exit;
end;
end;
Edit1.Text := '';
Edit2.Text := '';
ComboBox1.ItemIndex := 2;
RefreshUser;
end;
procedure TMgrUserF.Button2Click(Sender: TObject);
var
i : integer;
begin
for i := ListView1.Items.Count -1 downto 0 do
if ListView1.Items
.Selected then
try
DelUser(ListView1.Items.Caption);
ListView1.Items.Delete(i);
except
MessageDlg('删除用户<'+ListView1.Items.Caption+'>出错',mtError,[mbok],0);
end;
end;
end.主要的功能就是向一表中更新数据而已.