📄 unit4.pas
字号:
unit Unit4;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, Grids, DBGrids, DB;
type
TForm4 = class(TForm)
DataSource1: TDataSource;
DBGrid1: TDBGrid;
BitBtn1: TBitBtn;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
Button1: TButton;
SpeedButton3: TSpeedButton;
GroupBox1: TGroupBox;
procedure BitBtn1Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form4: TForm4;
implementation
uses Unit2, ADODB, Unit5;
{$R *.dfm}
procedure TForm4.BitBtn1Click(Sender: TObject);
begin
with DM.qrySQLStus do
begin
if Active then Active := False;
SQL.Text := 'Select * From Students';
Open;
DM.StudentsInfoDisplayHdl;
end;
end;
procedure TForm4.SpeedButton1Click(Sender: TObject);
var
iUserChoice : Integer;
strCmd : String;
bkMark : TBookmark; //书签的使用
begin
if DM.qrySQLStus.Active then
begin
iUserChoice := Application.MessageBox('','',MB_YESNO+MB_ICONQUESTION);
if iUserChoice = mrYes then
begin
bkMark := DM.qrySQLStus.GetBookmark; //保存书签
with DM.qryTmp do
begin
if Active then Active := False;
StrCmd := 'Delete From Students Where '
+ DM.qrySQLStus.Fields[0].FieldName
+ '='
+ QuotedStr(DM.qrySQLStus.Fields[0].AsString);
SQL.Text := strCmd;
ExecSQL;//当前使用的是非查询语句,故不能使用open
DM.qrySQLStus.Requery;//更新显示在用户面前的数据
DM.qrySQLStus.GotoBookmark(bkMark);//移动到书签
end;
end;
end;
end;
procedure TForm4.SpeedButton2Click(Sender: TObject);
var
strValStuName, strValStuClass : String;
strCmd : String;
bkMark : TBookmark;
begin
if not DM.qrySQLStus.Active then
begin
Application.MessageBox('','',MB_OK);
Exit;
end;
strValStuName := Trim(InputBox('修改','学生姓名',DM.qrySQLStus.Fields[1].AsString));
if strValStuName='' then
begin
Application.MessageBox('输入数据非法,不能修改','',MB_OK);
Exit;
end;
strValStuClass := Trim(InputBox('修改','学生班级',DM.qrySQLStus.Fields[2].AsString));
if strValStuClass='' then
begin
Application.MessageBox('输入数据非法,不能修改','',MB_OK);
Exit;
end;
with DM.qryTmp do
begin
bkMark := DM.qrySQLStus.GetBookmark;
if Active then Active := False;
strCmd := 'Update Students Set StuName=' + QuotedStr(strValStuName) + ','
+ 'StuClass=' + QuotedStr(strValStuClass) + ' '
+ 'Where StuNO=' + QuotedStr(DM.qrySQLStus.Fields[0].AsString);
SQL.Text := strCmd;
ExecSQL;
DM.qrySQLStus.Requery;
DM.qrySQLStus.GotoBookmark(bkMark);
end;
end;
procedure TForm4.Button1Click(Sender: TObject);
begin
if DM.qrySQLStus.Active then
DM.qrySQLStus.Close;
end;
procedure TForm4.SpeedButton3Click(Sender: TObject);
var
bkMark : TBookmark;
begin
Form5 := TForm5.Create(Self);
if Form5.ShowModal = mrOK then
begin
bkMark := DM.qrySQLStus.GetBookmark;
DM.qrySQLStus.Requery;
DM.qrySQLStus.GotoBookmark(bkMark);
end;
Form5.Free;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -