serQ.Close;
  serQ.SQL.Clear;
        //serQ.SQL.Add('select * from postcard where province=:province');
       //serQ.ParamByName('province').AsString := subsql;
{
  if(tpe = 'pro') then
      begin
        serQ.SQL.Add('select * from postcard where province=:province');
        serQ.ParamByName('province').AsString := subsql;
      end
   end; 
}
  serQ.Open;
为什么我使用//注释部分的写法就正确,但是使用{}注释部分的写法就错误呢?
请指教!

解决方案 »

  1.   

    if(tpe = 'pro') then
          begin
            serQ.SQL.Add('select * from postcard where province=:province');
            serQ.ParamByName('province').AsString := subsql;
          end//好像是因为多了这个end
       end; 
      

  2.   

    看你这个结构上,好像少了一个end, 看看是否是begin。。 end 不配对
    如果正常的话不会出现这样的问题
      

  3.   

    可能是如果tpe<>'pro',serq.sql.text='',serq.open;就錯了
      

  4.   

    确认tpe = 'pro'吗?如果tpe <> 'pro' serQ.SQL.Text=''执行serQ.Open;就会报错
      

  5.   


      procedure Tfrm.selBtnClick(Sender: TObject);
    var
      subsql, tpe: string;
    begin
      subsql := selEdt.Text;//输入
      tpe := typeLbl.Caption;//一个label  serQ.Close;
      serQ.SQL.Clear;
           // serQ.SQL.Add('select * from postcard where province=:province');
            //serQ.ParamByName('province').AsString := subsql;  if(tpe = 'pro') then
          begin
            serQ.SQL.Add('select * from postcard where province=:province');
            serQ.ParamByName('province').AsString := subsql;
          end
      else if(tpe = 'city') then
          begin
            serQ.SQL.Add('select * from postcard where city=:city');
            serQ.ParamByName('city').AsString := subsql;
          end
      else if(tpe = 'pid') then
          begin
            serQ.SQL.Add('select * from postcard where pid=:pid');
            serQ.ParamByName('pid').AsString := subsql;
          end
      end; 
      serQ.Open;
    end;
    这是全部代码,我在编译的时候就出错。
    这些sql语句是在button在click事件的时候才运行的
      

  6.   

    多了一个END;
    procedure Tfrm.selBtnClick(Sender: TObject);
    var
      subsql, tpe: string;
    begin
      subsql := selEdt.Text;//输入
      tpe := typeLbl.Caption;//一个label  serQ.Close;
      serQ.SQL.Clear;
           // serQ.SQL.Add('select * from postcard where province=:province');
            //serQ.ParamByName('province').AsString := subsql;  if(tpe = 'pro') then
          begin
            serQ.SQL.Add('select * from postcard where province=:province');
            serQ.ParamByName('province').AsString := subsql;
          end
      else if(tpe = 'city') then
          begin
            serQ.SQL.Add('select * from postcard where city=:city');
            serQ.ParamByName('city').AsString := subsql;
          end
      else if(tpe = 'pid') then
          begin
            serQ.SQL.Add('select * from postcard where pid=:pid');
            serQ.ParamByName('pid').AsString := subsql;
          end; 
      serQ.Open;
    end;这样应该没有问题.再试试吧.