电脑爱好者,提供IT资讯信息及各类编程知识文章介绍,欢迎大家来本站学习电脑知识。 最近更新 | 联系我们 RSS订阅本站最新文章
电脑爱好者
站内搜索: 
当前位置:首页>> delphi技术>>Delphi 与SQL编程(二)(4):

Delphi 与SQL编程(二)(4)

来源:远方网络 | 2005-12-31 9:40:50 | (有1807人读过)

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.


delphi技术热门文章排行
网站赞助商
购买此位置

 

关于我们 | 网站地图 | 文档一览 | 友情链接| 联系我们

Copyright © 2003-2024 电脑爱好者 版权所有 备案号:鲁ICP备09059398号