注册 登录
编程论坛 Delphi论坛

關於Delphi的一個查詢From的編程

tw920217 发布于 2011-06-07 11:17, 485 次点击
如題,剛入行Delphi不太久. 努力了1天.寫出如下代碼:

unit Projectfrm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, Grids, DBGrids, DB, ADODB, ComCtrls, StdCtrls;

type
  TProjectForm = class(TForm)
    lblDate: TLabel;
    lblStage: TLabel;
    cbStage: TComboBox;
    dtpSta: TDateTimePicker;
    dtpOver: TDateTimePicker;
    lbl: TLabel;
    dsStageDetail: TDataSource;
    DBConn: TADOConnection;
    qryStage: TADOQuery;
    dbGirdStage: TDBGrid;
    btnYes: TButton;
    procedure btnYesClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  ProjectForm: TProjectForm;

implementation

{$R *.dfm}

procedure TProjectForm.btnYesClick(Sender: TObject);
begin
  if StrToInt(cbStage.Text) in [010,020,030,110] then
  begin
    qryStage.Close;
    qryStage.SQL.Clear;
    qryStage.SQL.Add('select * from DStageDetail where Stage='''+cbStage.Text+'''');
    qryStage.SQL.Add(' and outputdate >= '+formatdatetime('yyyymmdd',dtpSta.Date) );
    qryStage.SQL.Add(' and ProdDate <= '+formatdatetime('yyyymmdd',dtpOver.Date) );
    qryStage.Open;
  end
  else
  begin
    qryStage.Close;
    qryStage.SQL.Clear;
    qryStage.SQL.Add('select * from DFQCDetail where Stage='''+cbStage.Text+'''');
    qryStage.SQL.Add(' and outputdate >= '+formatdatetime('yyyymmdd',dtpSta.Date) );
    qryStage.SQL.Add(' and outputdate <= '+formatdatetime('yyyymmdd',dtpOver.Date) );
    qryStage.Open;
  end;
end

------我是分割線------

具體我真的不太知道錯誤在哪里.因為我按照.net里面if-else的理論來看,沒問題應該是,cbStage是一個下拉框.
我有試過用: cbStage.Items.text in [...] 可是結果一樣運行不出來.我覺得應該是格式問題,代碼或許有點小問題,求
好心人指點.不然我要被老板罵一死. 剛學,不懂還望老鳥多多指教
5 回复
#2
tw9202172011-06-07 11:20
[Error] Projectfrm.pas(96): ';' expected but end of file found
[Fatal Error] Project1from.dpr(5): Could not compile used unit 'Projectfrm.pas'

提示錯誤。。其實,, 說實話,我壓根不知道這錯誤是啥.按中文翻譯出來也無法理解這個錯誤u
#3
zin59702011-06-07 12:26
上面是你全部的代码吗?是的话你就把最后的 end 换成

end;
end.
#4
tw9202172011-06-07 13:21
很感謝   請問為什么要這么做啊 。 我暫時還不太懂。因為還沒買書的原因。 只知道begin end相當于。net里的{} 請問這個Delphi里面的格式是怎樣啊 ?
#5
zin59702011-06-07 14:31
这是基本格式

单元最后以end.结尾   你上面的end只是与函数的begin匹配的  所以还少了一个end.
#6
tw9202172011-06-07 14:53
明白了.  谢谢哈. !~
1