listbox_addlist problem for a beginner

Started by borsa, May 11, 2011, 02:33:00 AM

Previous topic - Next topic

borsa

Hello,
I've programmed with DCL and now I'm trying to migrate to OpenDCL becauseit is more complete but I have some problems on the trials.
I try to fill a listbox with a list but does not write anything when display the dialog (only has a listbox)
I have read the forum Mesg but I'm lost. What am I doing wrong?

I tried addlist and setlist but no success

I'm sorry because English is not my native language

Thank you for teaching


Code (autolisp) Select

(defun C:ODCL0200 ( / )
 (getTowN)
 (command "_OPENDCL")
 (dcl_Project_Load "D:/design/lisp_cim/0300.odcl" T)
 (dcl_Form_Show 0300_ODCL02 )
 (princ)
)

(defun c:odcl_0200_OnInicialize (/)
;  (dcl_ListBox_Clear TowListN)
;  (dcl_Control_SetList 0300_ODCL02_ListBox1 aux01)
 (dcl_ListBox_AddList 0300_ODCL02_ListBox1 Aux01)

)

(defun GetTowN (/ aux01 )
 (setq k 12)
 (setq n 1)
 (setq aux01 (list nil))
 (Repeat k
   (setq aux01 (append aux01 (list (strcat "Item N." (Itoa n)))))
   (setq n (1+ n))
) )



roy_043

#1
Hi borsa,

There are two problems with your code:
- wrong name for initialize function
- GetTowN did not function correctly.

Code (autolisp) Select

(defun C:ODCL0200 ( / )
 (command "_OPENDCL")
 (dcl_Project_Load "D:/design/lisp_cim/0300.odcl" T)
 (dcl_Form_Show 0300_ODCL02 )
 (princ)
)

(defun c:0300_ODCL02_OnInitialize (/)
 (dcl_ListBox_Clear 0300_ODCL02_ListBox1)
 (dcl_ListBox_AddList 0300_ODCL02_ListBox1 (GetTowN))
)

(defun GetTowN (/ aux01 n k)
 (setq k 12)
 (setq n 1)
 (repeat k
   (setq aux01 (append aux01 (list (strcat "Item N." (Itoa n)))))
   (setq n (1+ n))
 )
 aux01
)


Note: you must check the initialize event for your form.

Regards, Roy.

borsa

Hi Roy

Just one question, have you checked your lisp code attached?. I've loaded your code in cad and the listbox is still empty. Perhaps I have another mistake but I want to be sure.

In my lisp code "Aux01" is already alist so I can add it to the listbox with the function addlist and not through the function "GetTowN" as in your code. isnĀ“t it?

Thanks for your help.

BazzaCAD

Roy's code is correct.
If it's not working for you, you probably don't have the "OnInitialize" even checked, or you changed the name of one of your controls.
If you attach your .lsp & .odcl we can probably track down the issue.
a.k.a.
Barry Ralphs
barryDOTralphsATgmailDOTcom

roy_043

@ BazzaCAD: Thank you for that confirmation. And also thank you for your great OpenDCL Beginners Tutorial!

@ borsa:

Your function (GetTowN) doesn't work the way you think. Because aux01 is a local variable in (GetTowN) using

(dcl_ListBox_AddList 0300_ODCL02_ListBox1 Aux01)

in c:odcl_0200_OnInicialize will not work properly.
And after this code:

(setq aux01 (list nil))

aux01 is not an empty list but a list with one element: (nil)

Regards, Roy.

Fred Tomke

Hi,

in addition to what was written I want to add dcl_control_setlist, because the listbox control still contains its items when re-showing the form:

Code (autolisp) Select

(defun c:0300_ODCL02_OnInitialize (/) 
  (dcl_ListBox_SetList 0300_ODCL02_ListBox1 (GetTowN)) 
); c:0300_ODCL02_OnInitialize


Regards, Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

borsa

I'm sorry. I'm checking the dialog and note the Initialize event is not marke, may be the result of all the changes I do to try and also my mistakes.

Now the code runs properly.

Thanks to everyone

roy_043

@ Fred: No doubt you mean: dcl_Control_SetList.


Fred Tomke

Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]