meflying 发表于 2003-2-9 15:23:00

为何出错!

(defun C:HELLO( / dcl_id )
(setq dcl_id (load_dialog "d:\\wjh\\study\\autolisp\\tmp.dcl"));加载 DCL 文件
(if (not (new_dialog "hello" dcl_id))                ;初始化对话框
    (exit)                                        ;如果不工作就退出
)
(start_list "p_list" 2)
(add_list "comghit")
;!!!---------------------*****出错地方*****----------------------------!!!
;如果加上下面这句,程序就死掉,似乎进了死循环,为什么?是用法不对吗?
;(add_list "comghit")
(end_list)
(start_dialog)                ;显示对话框
(unload_dialog dcl_id)        ;卸载 DCL 文件
(princ)

)

CAD菜鸟 发表于 2003-2-9 16:09:00

add_list之前,先用start_list调用列表

leon 发表于 2003-2-9 16:10:00

回复

(defun C:HELLO( / dcl_id )
(setq dcl_id (load_dialog "d:/tmp.dcl"))
;问题出在这里,如果(new_dialog "hello" dcl_id)成功,则你无法再去控制对话框了.
;(if (not (new_dialog "hello" dcl_id))
;    (exit)
;)
(if (new_dialog "hello" dcl_id)
      (progn
         (start_list "test" 2)
         (add_list "comghit")
         (add_list "comghit")
         (end_list)
         (start_dialog)
         (unload_dialog dcl_id)
           (print dcl_id)
      )
)
(princ)
)


hello:dialog{
      label="hello";
      :popup_list {
            label="";
          key="test";
          width=15;
          list="1";
      }
      : row {
            fixed_width = true;
            alignment = right;
            : button {
                     label = "下一步";
                     key = "next";
                     width = 8;
            }
            : button {
                     label = "取消";
                     key = "cancel";
                     is_cancel = true;
                     width = 8;
            }
      }
}

meflying 发表于 2003-2-10 09:34:00

可我看不出你的和我的有什么区别

我觉得你并没有改变什么东西,

if expression1 then expression 2

if not expression1 then exit
expression 2

不都是expression1为真时执行expression2吗?

而且如果是你说的那种错误,应该是提示出错然后退出程序,不我的是程序就没有任何动静,也无法操作,只能结束任务。

meflying 发表于 2003-2-10 09:35:00

我用了,而且第一次调用add_list都对,就是连续调用两次就出错。

leon 发表于 2003-2-10 10:18:00

回复

请注意这里:
(if (not (new_dialog "hello" dcl_id))
      (exit)
)
我已经说过,只要执行了(new_dialog "hello" dcl_id)而且成功的话,他就会显示出对话框,(start_dialog)只是表示你要开始控制对话框而已。我说的重点在于"控制",正因为你无法控制,所以才导致3键退出,不知道你明白没有。所以我是从来都不这样使用的。

leon 发表于 2003-2-10 11:01:00

回复

sorry,我是看着我的贴子给你回复的,的确有不妥的地方。
我再看看,不过你按我那种方法使用是绝对没错的。

meflying 发表于 2003-2-10 11:01:00

对不起,我还是觉得一样...

你在仔细看看,你和我的程序只是一个判断语句的两种写法,或许判断的另一种结果所执行的语句不同(我的是(exit),你的是继续程序以后的内容),但这个判断语句在这里的判断结果应该都是执行(start_list)...的,而且我也执行了你的程序,结果一样。
    所以我怀疑是不是CAD的问题,我的CAD是盗版的。
          还是很感谢您的回答!!!

meflying 发表于 2003-2-10 11:03:00

我执行了,还是一样,可能是我的CAD的问题了

leon 发表于 2003-2-10 11:09:00

回复

不用客气,大家一起提高嘛。
我又重新试了你的程序,结果是没什么问题。我现在贴上完整的代码供你参考。
(defun C:HELLO( / dcl_id )
(setq dcl_id (load_dialog "d:/tmp.dcl"))
(if (not (new_dialog "hello" dcl_id))
      (exit)
)
(start_list "test" 2)
(add_list "comghit")
(add_list "comghit")
(end_list)
(start_dialog)
(unload_dialog dcl_id)
(princ)
)


hello:dialog{
      label="hello";
      : list_box {
            label="";
            key="test";
            width=15;
            list="1";
      }
      : row {
            fixed_width = true;
            alignment = right;
            : button {
                     label = "确定";
                     key = "accept";
                     width = 8;
            }
            : button {
                     label = "取消";
                     key = "cancel";
                     is_cancel = true;
                     width = 8;
            }
      }
}

如果可以的话,你可以上传你的代码,大家研究一下。或者你可以去广杰居下在2002迷你中文版,很好用。前提是你是用98。
页: [1] 2
查看完整版本: 为何出错!