我做了一个小数据库,
在删除数据的时候我想要实现以下功能,
在点删除按钮的时候,先弹出是否确定删除的对话框,
上面有是,否和取消三个按钮,当点是的时候,如果数据库中还有数据,则删除,否则弹出数据库已空的对话框,当点击否和取消的时候退出.
代码我是这么写的:
if (application.messagebox('确定删除?','提示',mb_yesnocancel+mb_icominformation)=idyes) and (table1.record>0) 
then
table1.delete
else if  application.messagebox('确定删除?','提示',mb_yesnocancel+mb_icominformation)=idno 
then
exit
else if if application.messagebox('确定删除?','提示',mb_yesnocancel+mb_icominformation)=idcancel  
then
exit;
else 
showmessage('表已空')
可结果并不是我所想的,
那个确定删除的对话框弹出好几次,
这是怎么回事呢?大家帮我看看,
要想实现我说的功能,
应该怎么写呢?

解决方案 »

  1.   

    if not ((application.messagebox('确定删除?','提示',mb_yesnocancel+mb_icominformation)=idyes) and (table1.record>0)) 
    then
      exit
    else
      table1.delete;
    showmessage('表已空');
      

  2.   

    试试以下的代码:
    case (application.messagebox('确定删除?','提示',mb_yesnocancel+mb_icominformation) of
    idyes: 
      begin
        if table1.recordcount>1 then
           table1.delete
        else
           showmessage('表已空!');
        exit;
      end;
    IDno:
       exit;
    idcancel:
       exit;
    end;呵呵,我这里没有机器,我觉得至少这个思路是比你的那个要好一点点了。
      

  3.   

    if (application.messagebox('确定删除?','提示',mb_yesnocancel+mb_icominformation)=idyes) and (table1.record>0) 
    then
    table1.delete
    else exit;showmessage('表已空')
      

  4.   

    if not (table1.record>0) then showmessage('表已空')
    else if (application.messagebox('确定删除?','提示',mb_yesnocancel+mb_icominformation)=idyes) 
    then
    table1.delete
      

  5.   

    我想应该是这样,提醒这位老兄,写代码注意不能太乱!!!!!!!var
      Back:Integer;
    .....
      Back:=application.messagebox('确定删除?','提示',mb_yesnocancel+mb_icominformation);
      
    if Back=idYes then
      if table1.record>0 then
        table1.delete
      else
        showmessage('表已空');
      end
    else
      exit;
    end;
      
    else if  application.messagebox('确定删除?','提示',mb_yesnocancel+mb_icominformation)=idno 
    then
    exit
    else if if application.messagebox('确定删除?','提示',mb_yesnocancel+mb_icominformation)=idcancel  
    then
    exit;
    else 
    showmessage('表已空')
      

  6.   

    对不起,由于太忙,有误,下面部分是我复制的是楼主的代码,应删去!!!
    正确的应该是:
    我想应该是这样,提醒这位老兄,写代码注意不能太乱!!!!!!!var
      Back:Integer;
    .....
      Back:=application.messagebox('确定删除?','提示',mb_yesnocancel+mb_icominformation);
      
    if Back=idYes then
      if table1.record>0 then
        table1.delete
      else
        showmessage('表已空');
      end
    else
      exit;
    end;
      

  7.   

    对不起,由于太忙,有误,下面部分是我复制的是楼主的代码,应删去!!!
    正确的应该是:
    我想应该是这样,提醒这位老兄,写代码注意不能太乱!!!!!!!var
      Back:Integer;
    .....
      Back:=application.messagebox('确定删除?','提示',mb_yesnocancel+mb_icominformation);
      
    if Back=idYes then
      if table1.record>0 then
        table1.delete
      else
        showmessage('表已空')
    else
      exit;
    抱歉!我太粗心,上面的代码中多了两个End;