sample of (dcl_form_show) with variable

Started by khann, May 11, 2009, 09:57:28 PM

Previous topic - Next topic

(dcl_form_show) with variable

no opt
0 (0%)
no opt
0 (0%)

Total Members Voted: 0

khann

Hi.
I've just start to learn ODCL.
ODCL seems great to me.
I have a question.
When using (dcl_form_show) can I use the form name with variable?


example :
...
(setq *myForm "ODCL_Form1")
(dcl_form_show *myForm )
...


Thanks.

Kerry

Yes.




Did you know that ODCL has variable names for each of your forms and Controls ?
ie
MyProject_MyForm
MyProject_MyForm_Label1

Code (autolisp) Select

(defun C:MyCommand (/ Result)
  (command "_OPENDCL") ; Load OpenDCL Runtime
  (if (dcl_Project_Load "MyProject") ; Load project data from MyProject.odcl
    (progn
      (setq Result (dcl_Form_Show MyProject_MyForm))
      ; Note that this code does not execute until *after* the dialog is closed!
      (if (= Result 1) (DoSomething))
    )
  )
  (princ)
)
(defun c:MyProject_MyForm_OnInitialize (/)
  (dcl_Control_SetCaption MyProject_MyForm_Label1 "Hello World!")
)
(defun c:MyProject_MyForm_CloseButton_OnClicked (/)
  (dcl_Form_Close MyProject_MyForm)
)


Perfection is not optional.
My other home is TheSwamp

khann

Yes. I've read that in the Help and tutorial.
So I want to make the Form name with (strcat) Fun.

Like this :

(setq *form_name "Form1")
(setq *myForm (strcat "ODCL" *form_name ))

(dcl_form_show *myForm )

Can this be possible?

Fred Tomke

#3
Sure. There are several samples in my mind:

1. Depending on which form should be shown you put the form object into a variable. I do it so with controls doing similiar the same. In this sample you have to know the forms which may be shown.
Sample:

Code (autolisp) Select

(cond
  ((= intCondition 1) (setq oForm MyProj_Form1))
  ((= intCondition 2) (setq oForm MyProj_Form2))
  ((= intCondition 3) (setq oForm MyProj_Form3))
  ((= intCondition 4) (setq oForm MyProj_Form4))
); cond

(if oForm (dcl_form_show oForm))


2. If you don't know the form exactly or you want to run a loop there are two different ways

a) with strings

Code (autolisp) Select

(defun form_show (strForm)
  (if (member strForm (dcl_project_getforms "MyProject"))
    (dcl_form_show "MyProject" strForm)
  ); if
); form_show

(form_show "MyForm1")


b) with objects

Code (autolisp) Select

(defun form_show (strForm / oForm)
  (if (setq oForm (eval (read (strcat "MyProject_" strForm))))
    (dcl_form_show oForm)
  ); if
); form_show

(form_show "MyForm1")


Hope that helps.

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

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

khann

 :D Thanks Fred!
That's just what I want.
I didn't place the (eval) at proper position.

It saves me from making of hundreds variables.