delphi使用SQL的教程8
{ Use a resource protection block in case an exception is raised. This
ensures that the memory allocated for the Results form is released. }
try
with frmQuery do
begin
Screen.Cursor := crHourglass;
if Query1.Active then Query1.Close;
Query1.DatabaseName := strAlias; {set the alias the query poitns to}
Query1.SQL.clear; { empty existing SQL in the query }
Query1.SQL.Add(strQuery); { add query string to query object }
Query1.Active := True; { try to run the query }
Screen.Cursor := crDefault;
if Query1.Active then
begin
{ If the query didn’t return any records, there’s no point in
displaying the form. In that event, raise an exception. }
if Query1.RecordCount < 1 then
raise Exception.create(’No records matched your criteria.
Please try again.’ );
{ write a message to the browse form’s status line }
if strField = ’’ then
Panel3.Caption := ’Now showing all records from ’ + strTable
+ ’...’
else
Panel3.Caption := ’Now showing ’+ strTable +’ where ’+ strField
+’ contains values equal to ’+ strValue + ’...’;
{ show the form }
ShowModal;
end;
end;
finally
frmQuery.Free;
end;
end;
end.
unit RSLTFORM;
interface
uses
SysUtils, Windows, Messages, Classes, Graphics, Controls, StdCtrls, DB,
Forms, DBCtrls, DBGrids, DBTables, Buttons, Grids, ExtCtrls, Dialogs;
type
TResultForm = class(TForm)
DBGrid1: TDBGrid;
DBNavigator: TDBNavigator;
Panel1: TPanel;
DataSource1: TDataSource;
Panel2: TPanel;
Panel3: TPanel;
Query1: TQuery;
SpeedButton2: TSpeedButton;
Panel4: TPanel;
SpeedButton1: TSpeedButton;
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
end;
var
ResultForm: TResultForm;
implementation
{$R *.DFM}
procedure TResultForm.SpeedButton1Click(Sender: TObject);
begin
Close;
end;
procedure TResultForm.SpeedButton2Click(Sender: TObject);
var
strText: string; { Variable to hold display text }
iCounter: Integer; { Loop counter variable }
begin
{ Build a string containing the query }
strText := ’’;
for iCounter := 0 to Query1.SQL.Count - 1 do
strText := strText + Query1.SQL[iCounter];
{ Display the query text }
MessageDlg(’The underlying query is: ’ + #10 + #10 + strText,
mtInformation, [mbOK], 0 );
end;
end.
转载于:https://www.cnblogs.com/JTeacher/archive/2012/11/19/2776918.html
- 点赞
- 收藏
- 分享
- 文章举报
- Delphi中本年、本月、本周第一天和最后一天
- delphi xml 添加节点
- delphi xml 查找节点
- delphi 中 Record ,packet Record
- Delphi的MessageBox的用法
- Delphi 将DBGrid中的内容导出到Excel
- Delphi把窗体设为bsnone时如何拖动窗体
- Delphi向QQ2011窗口发送登录消息
- delphi编程中的棘手问题;求指教!
- 在DELPHI程序中自动设置ODBC数据源
- Delphi粗边框
- 由Delphi程序改写Sql(2000)的存储过程
- Delphi发email
- 用Delphi 向量算法 判断点是否在线上
- Delphi 删除控件问题
- 继续Delphi调用Wcf
- Delphi 调用WCF 搞定啦
- Quick Report 说明 for delphi 7
- DELPHI7下用superobject读取中国天气网的JSON数据的天气预报
- 刚学 Delphi 请多指教