mainfrm.pas
来自「《Delphi开发人员指南》配书原码」· PAS 代码 · 共 55 行
PAS
55 行
unit MainFrm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, DBGrids, DB, DBTables, StdCtrls;
type
TMainForm = class(TForm)
dbMain: TDatabase;
lbTables: TListBox;
dsMain: TDataSource;
dbgMain: TDBGrid;
qryMain: TQuery;
lblTables: TLabel;
procedure FormCreate(Sender: TObject);
procedure lbTablesClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.DFM}
procedure TMainForm.FormCreate(Sender: TObject);
begin
{ First, get a list of table names for the user to select }
Session.GetTableNames(dbMain.DatabaseName, '', False, False, lbTables.Items);
end;
procedure TMainForm.lbTablesClick(Sender: TObject);
{ Define a constant string from which the SQL string will be built }
const
SQLString = 'SELECT * FROM %s';
begin
with qryMain 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, [lbTables.Items[lbTables.ItemIndex]]));
Open; { Now open Query1 with the new statement }
end;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?