📄 mainfrm.pas
字号:
unit MainFrm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, DBGrids, DB, DBTables, StdCtrls;
type
TMainForm = class(TForm)
dbMain: TDatabase;
lbFields: TListBox;
tblParts: TTable;
dsParts: TDataSource;
dbgParts: TDBGrid;
qryParts: TQuery;
lblFields: TLabel;
procedure FormCreate(Sender: TObject);
procedure lbFieldsClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.DFM}
procedure TMainForm.FormCreate(Sender: TObject);
begin
{ Retrieve a list of field names from the PARTS.DB table so that
the use can select the field on which to sort the query. These
fields names are placed into a TListBox. }
tblParts.Open;
try
tblParts.GetFieldNames(lbFields.Items);
finally
tblParts.Close;
end;
end;
procedure TMainForm.lbFieldsClick(Sender: TObject);
{ Define a constant string from which the SQL string will be built }
const
SQLString = 'SELECT * FROM PARTS ORDER BY %s';
begin
with qryParts do
begin
Close; // Make sure the query is closed.
SQL.Clear; // Clear any previous SQL statement.
{ Now add the new SQL statement constructed with the format
function }
SQL.Add(Format(SQLString, [lbFields.Items[lbFields.ItemIndex]]));
Open; { Now open Query1 with the new statement }
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -