if(process_no.Text <> '') and (winprg.Text <> '') then
 begin
   try
     with DM.qryMenzheng do
     begin
       Close;
       SQL.Clear;
       SQL.Add(str);
       SQL.Add(' where a.process_no =' +process_no.Text);
       SQL.Add(' AND a.winprg =' + winprg.Text);
       SQL.Add(' order by a.patient_no');
       Open;
       {*******Add by ice 2003-7-26 begin*******}
       if (DM.qryMenzheng.RecordCount < 1 ) then
         ShowMessage('对不起,没有找到您所要信息,请检查您输入的号码是否正确!');
         process_no.Text := '';
         process_no.SetFocus;
         Screen.Cursor := crDefault;
         exit;
         {*******Add by ice 2003-7-26 end ******* }
         for i:= 0 to dbgMenZheng.Columns.Count - 1 do
         begin
           dbgMenZheng.Columns[i].Width := 80;
         end;
       end;
   except
     Application.MessageBox('读取数据库时失败', '错误', MB_ICONSTOP);
   end;
     Screen.Cursor := crDefault;
 end
 else
 begin
     ShowMessage('请输入要查询的发票流水号和站号');
     if(process_no.Text = '') then
       process_no.SetFocus
     else
       winprg.SetFocus;
     Exit;
 end;提示错误: if和else不匹配

解决方案 »

  1.   

    if (DM.qryMenzheng.RecordCount < 1 ) then
           begin  //////////这里
             ShowMessage('对不起,没有找到您所要信息,请检查您输入的号码是否正确!');
             process_no.Text := '';
             process_no.SetFocus;
             Screen.Cursor := crDefault;
             exit;
             {*******Add by ice 2003-7-26 end ******* }
             for i:= 0 to dbgMenZheng.Columns.Count - 1 do
             begin
               dbgMenZheng.Columns[i].Width := 80;
             end;
           end;
      

  2.   

    同:hch_45(んこん),尽量把try写到用的地方,begin……end严格对齐,就不会出现此类错误。with……begin……end   try……except……end
      

  3.   

    你只要把代码层层对齐就知道IF/ELSE是否配套了。
    单从这段程序代码来看,IF/ELSE是配套的,
    如果在if (DM.qryMenzheng.RecordCount < 1 ) then的后面加上BEGIN,那么WTITH的END就没有了。
    但我认为你的程序从逻辑上说不过去,你应该看下程序的其他位置。
      

  4.   

    if(process_no.Text <> '') and (winprg.Text <> '') then
     begin
       try
         with DM.qryMenzheng do
         begin
           Close;
           SQL.Clear;
           SQL.Add(str);
           SQL.Add(' where a.process_no =' +process_no.Text);
           SQL.Add(' AND a.winprg =' + winprg.Text);
           SQL.Add(' order by a.patient_no');
           Open;
           {*******Add by ice 2003-7-26 begin*******}
           if (DM.qryMenzheng.RecordCount < 1 ) then
           begin
             ShowMessage('对不起,没有找到您所要信息,请检查您输入的号码是否正确!');
             process_no.Text := '';
             process_no.SetFocus;
             Screen.Cursor := crDefault;
             exit;
             {*******Add by ice 2003-7-26 end ******* }
             for i:= 0 to dbgMenZheng.Columns.Count - 1 do
             begin
               dbgMenZheng.Columns[i].Width := 80;
             end;
           end;
         end;
       except
         Application.MessageBox('读取数据库时失败', '错误', MB_ICONSTOP);
       end;
         Screen.Cursor := crDefault;
     end
     else
     begin
         ShowMessage('请输入要查询的发票流水号和站号');
         if(process_no.Text = '') then
           process_no.SetFocus
         else
           winprg.SetFocus;
         Exit;
     end;
      

  5.   

    如果是像楼上说得那样的话,那么
    for i:= 0 to dbgMenZheng.Columns.Count - 1 do
    begin
     dbgMenZheng.Columns[i].Width := 80;
    end;
    又有什么意义????他的前面已经Exit了,唉,好像楼主的函数没有说明白,怎么看起来逻辑有问题
      

  6.   

    兄弟我建议你写代码的时候,如果写了if begin最好马上写上end
    这样做肯定不会出现这样的问题
      

  7.   

    for i:= 0 to dbgMenZheng.Columns.Count - 1 do
    begin
     dbgMenZheng.Columns[i].Width := 80;
    end;可以写成,少一个让你眼花的beginfor i:= 0 to dbgMenZheng.Columns.Count - 1 do
      dbgMenZheng.Columns[i].Width := 80;
      

  8.   


    由于 PASCAL 语言中所有语句的结束都是用 END,对于程序阅读有一定困难
    建议这样if Exp1 = Exp2 then
    begin
      ShowMessage('1');
    end else begin
      with Form1 do
      begin
        ShowMessage('1');
      end; // with Form1 do
    end; // if Exp1 = Exp2
      

  9.   

    同意hch_45(口口口),不过IF 语句最好都加上BEGIN END。
      

  10.   


           if (DM.qryMenzheng.RecordCount < 1 ) then         //这里少了一个"Begin"         ShowMessage('对不起,没有找到您所要信息,请检查您输入的号码是否正确!');
             process_no.Text := '';
             process_no.SetFocus;
             Screen.Cursor := crDefault;
             exit;
             {*******Add by ice 2003-7-26 end ******* }
             for i:= 0 to dbgMenZheng.Columns.Count - 1 do
             begin
               dbgMenZheng.Columns[i].Width := 80;
             end;
           end;
      

  11.   

    光看这段代码来说,if-else是配对的
    我觉的逻辑上有错误,再根据你的程序实现的功能来检查检查
    尽可能的减少这种套接的写法