📄 main.~pas
字号:
unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DBTables, DB, Grids, DBGrids, StdCtrls;
type
TForm1 = class(TForm)
DataSource1: TDataSource;
DBGrid1: TDBGrid;
tblEmployee: TTable;
Label1: TLabel;
edtKey: TEdit;
lblResult: TLabel;
btnClose: TButton;
GroupBox1: TGroupBox;
btnGotoNearest: TButton;
btnGotoKey: TButton;
GroupBox2: TGroupBox;
btnFindKey: TButton;
btnFindNearest: TButton;
GroupBox3: TGroupBox;
btnLocate: TButton;
cbxCaseInsensitive: TCheckBox;
cbxPartialKey: TCheckBox;
Label2: TLabel;
Label3: TLabel;
edtFirstName: TEdit;
edtLastName: TEdit;
procedure btnGotoKeyClick(Sender: TObject);
procedure btnGotoNearestClick(Sender: TObject);
procedure btnFindKeyClick(Sender: TObject);
procedure btnFindNearestClick(Sender: TObject);
procedure btnLocateClick(Sender: TObject);
procedure btnCloseClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//执行GotoKey查询
procedure TForm1.btnGotoKeyClick(Sender: TObject);
begin
with tblEmployee do
begin
if IndexFieldNames = '' then
IndexFieldNames := 'EmpNo';
SetKey;
FieldByName('EmpNo').AsString := edtKey.Text;
if GotoKey then
lblResult.Caption := '查找成功!'
else
lblResult.Caption := '查找失败';
end;
end;
//执行GotoNearest查询
procedure TForm1.btnGotoNearestClick(Sender: TObject);
begin
with tblEmployee do
begin
if IndexFieldNames = '' then
IndexFieldNames := 'EmpNo';
SetKey;
FieldByName('EmpNo').AsString := edtKey.Text;
GotoNearest;
end;
lblResult.Caption := '模糊查找完成!'
end;
//执行FindKey查询
procedure TForm1.btnFindKeyClick(Sender: TObject);
begin
with tblEmployee do
begin
if IndexFieldNames = '' then
IndexFieldNames := 'EmpNo';
if FindKey([edtKey.Text]) then
lblResult.Caption := '查找成功!'
else
lblResult.Caption := '查找失败';
end;
end;
//执行FindNearest查询
procedure TForm1.btnFindNearestClick(Sender: TObject);
begin
with tblEmployee do
begin
if IndexFieldNames = '' then
IndexFieldNames := 'EmpNo';
FindNearest([edtKey.Text]);
end;
lblResult.Caption := 'FindNearest模糊查找完成!'
end;
//执行Locate查询
procedure TForm1.btnLocateClick(Sender: TObject);
var lo:TLocateOptions ;
begin
//设置是否大小写敏感
if cbxCaseInsensitive.Checked then
Include(lo, loCaseInsensitive)
else
Exclude(lo, loCaseInsensitive);
//设置是否执行近似查询
if cbxPartialKey.Checked then
Include(lo, loPartialKey)
else
Exclude(lo, loPartialKey);
with tblEmployee do
begin
if Locate('FirstName;LastName', VarArrayof([edtFirstName.Text,
edtLastName.Text]), lo) then
lblResult.Caption := '查找成功!'
else
lblResult.Caption := '查找失败';
end;
end;
procedure TForm1.btnCloseClick(Sender: TObject);
begin
Close;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -