[原创作品]模仿面向对象实现动态DCL代码生成器(开源)
本帖最后由 不死猫 于 2015-3-22 22:52 编辑动态DCL的方法有很多,我曾经也发过3种制作的方案.
今天带来的是更加直观的模仿面向对象,为控件赋属性的方法.
定义函数如下:
(dcl-make 名称)
用于定义一个新的dcl控件
(dcl-put 控件 属性 值)
用于设置控件的属性
(dcl-get 控件 属性)
用于获取控件的属性
(dcl-add 控件 子控件)
用于把子控件添加到父控件上面
这几个函数源码在下面提供免费下载.
源码免币下载:
====================================
简单测试1(defun c:tt1()
(vl-load-com)
;定义控件并设置属性
(setq dialog (dcl-make "dialog"))
(dcl-put 'dialog "name" "test")
(dcl-put 'dialog "label" "测试1")
(setq button1 (dcl-make "button"))
(dcl-put 'button1 "key" "button1")
(dcl-put 'button1 "label" "点我")
(dcl-put 'button1 "width" "20")
(dcl-put 'button1 "height" "1")
;定义完成
;从内向外添加
(dcl-add 'dialog 'button1)
;制作
(setq dcl (dcl-convert dialog))
(dcl-show dcl)
)执行结果:
简单测试2(defun c:tt2()
(vl-load-com)
;定义控件并设置属性
(setq dialog (dcl-make "dialog"))
(dcl-put 'dialog "name" "test")
(dcl-put 'dialog "label" "test")
(setq boxed_column1 (dcl-make "boxed_column"))
(dcl-put 'boxed_column1 "label" "ok")
(setq edit_box1 (dcl-make "edit_box"))
(dcl-put 'edit_box1 "key" "editbox1")
(dcl-put 'edit_box1 "label" "输入1")
(dcl-put 'edit_box1 "width" "20")
(dcl-put 'edit_box1 "height" "1")
(setq edit_box2 (dcl-make "edit_box"))
(dcl-put 'edit_box2 "key" "editbox2")
(dcl-put 'edit_box2 "label" "输入2")
(dcl-put 'edit_box2 "width" "20")
(dcl-put 'edit_box2 "height" "1")
;定义完成
;从内向外添加
(dcl-add 'boxed_column1 'edit_box1)
(dcl-add 'boxed_column1 'edit_box2)
(dcl-add 'dialog 'boxed_column1)
;制作
(setq dcl (dcl-convert dialog))
(dcl-show dcl)
)执行结果:
简单测试3(defun c:tt3()
(vl-load-com)
;定义控件并设置属性
(setq dialog (dcl-make "dialog"))
(dcl-put 'dialog "name" "test")
(dcl-put 'dialog "label" "test")
(setq boxed_column1 (dcl-make "boxed_column"))
(dcl-put 'boxed_column1 "label" "ok")
(setq boxed_row1 (dcl-make "boxed_row"))
(dcl-put 'boxed_row1 "label" "列表")
(setq edit_box1 (dcl-make "edit_box"))
(dcl-put 'edit_box1 "key" "editbox1")
(dcl-put 'edit_box1 "label" "输入1")
(dcl-put 'edit_box1 "width" "20")
(dcl-put 'edit_box1 "height" "1")
(setq edit_box2 (dcl-make "edit_box"))
(dcl-put 'edit_box2 "key" "editbox2")
(dcl-put 'edit_box2 "label" "输入2")
(dcl-put 'edit_box2 "width" "20")
(dcl-put 'edit_box2 "height" "1")
(setq edit_box3 (dcl-make "list_box"))
(dcl-put 'edit_box3 "key" "list_box1")
(dcl-put 'edit_box3 "width" "20")
(dcl-put 'edit_box3 "height" "20")
;定义完成
;从内向外添加
(dcl-add 'boxed_column1 'edit_box1)
(dcl-add 'boxed_column1 'edit_box2)
(dcl-add 'boxed_row1 'edit_box3)
(dcl-add 'dialog 'boxed_column1)
(dcl-add 'dialog 'boxed_row1)
;制作
(setq dcl (dcl-convert dialog))
(dcl-show dcl)
)执行结果
下面玩个小循环(defun c:tt4()
;定义控件并设置属性
(setq dialog (dcl-make "dialog"))
(dcl-put 'dialog "name" "test")
(dcl-put 'dialog "label" "测试4")
(setq i 1 num 10)
(repeat num
(set (read (strcat "boxed_column" (itoa i))) (dcl-make "boxed_column"))
(dcl-put (read (strcat "boxed_column" (itoa i))) "label" ":)")
(setq i (1+ i))
)
(setq i 1)
(repeat num
(set (read (strcat "button" (itoa i))) (dcl-make "button"))
(dcl-put (read (strcat "button" (itoa i))) "key" (strcat "button" (itoa i)))
(dcl-put (read (strcat "button" (itoa i))) "label" (strcat "点我" (itoa i)))
(dcl-put (read (strcat "button" (itoa i))) "width" "20")
(dcl-put (read (strcat "button" (itoa i))) "height" "1")
(setq i (1+ i))
)
;定义完成
;从内向外添加
(setq i 1)
(repeat (1- num)
(dcl-add (read (strcat "boxed_column" (itoa i))) (read (strcat "button" (itoa i))))
(dcl-add (read (strcat "boxed_column" (itoa (1+ i)))) (read (strcat "boxed_column" (itoa i))))
(setq i (1+ i))
)
(dcl-add 'dialog (read (strcat "boxed_column" (itoa i))))
;制作
(setq dcl (dcl-convert dialog))
(dcl-show dcl)
)执行结果:
源代码写了56行,就直接发了.
猫老师的作品,我是需要三顾才能明白,几年后再来 跟随猫老师的脚步,慢慢学习 支持,很给力 猫老师又出精品了 横向的控件制作只需添加一个row即可(defun c:tt22()
;定义控件并设置属性
(setq dialog (dcl-make "dialog"))
(dcl-put 'dialog "name" "test")
(dcl-put 'dialog "label" "test")
(setq boxed_column1 (dcl-make "boxed_column"))
(dcl-put 'boxed_column1 "label" "ok")
(setq row1 (dcl-make "row"))
(setq edit_box1 (dcl-make "edit_box"))
(dcl-put 'edit_box1 "key" "editbox1")
(dcl-put 'edit_box1 "label" "输入1")
(dcl-put 'edit_box1 "width" "20")
(dcl-put 'edit_box1 "height" "1")
(setq edit_box2 (dcl-make "edit_box"))
(dcl-put 'edit_box2 "key" "editbox2")
(dcl-put 'edit_box2 "label" "输入2")
(dcl-put 'edit_box2 "width" "20")
(dcl-put 'edit_box2 "height" "1")
;定义完成
;从内向外添加
(dcl-add 'row1 'edit_box1)
(dcl-add 'row1 'edit_box2)
(dcl-add 'boxed_column1 'row1)
(dcl-add 'dialog 'boxed_column1)
;制作
(setq dcl (dcl-convert dialog))
(dcl-show dcl)
)
不错,很好的示例 猫兄又鼓捣出新东西了 哇!又有好东西了!支持。 不错的思路 支持一个! 好东西都要玩隐藏。