OpenDCL Forums

OpenDCL => Runtime/AutoLISP => Topic started by: khann on May 11, 2009, 09:57:28 PM

Poll
Question: (dcl_form_show) with variable
Option 1: no opt votes: 0
Option 2: no opt votes: 0
Title: sample of (dcl_form_show) with variable
Post by: khann on May 11, 2009, 09:57:28 PM
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.
Title: Re: sample of (dcl_form_show) with variable
Post by: Kerry on May 11, 2009, 10:25:23 PM
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)
)


Title: Re: sample of (dcl_form_show) with variable
Post by: khann on May 12, 2009, 12:30:00 AM
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?
Title: Re: sample of (dcl_form_show) with variable
Post by: Fred Tomke on May 12, 2009, 01:48:07 AM
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
Title: Re: sample of (dcl_form_show) with variable
Post by: khann on May 12, 2009, 05:53:19 AM
 :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.