Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Where to declare variables in dialog script
#1
if I put the below code between the "messages" and "sel message", test gets outputted many times.

Code:
Copy      Help
out "test"

The problem is that I declare variables exactly there, I also declare ICsv's there.

Example:

I am referring at the position where the following comment is:
Code:
Copy      Help
;; variables declared here:

Function test_variables_dlg
Code:
Copy      Help
;\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages


;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;3 QM_Grid 0x56031041 0x200 42 22 96 48 "0[]A[]B"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040105 "" "" "" ""

ret
;messages

;; variables declared here:
str- test1
str- test2
str- test4
ICsv- list_csv
list_csv=CreateCsv()
list_csv.ColumnCount=5
list_csv.Separator="*"
list_csv.FromQmGrid(id(3 hDlg))

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

Does this mean for example "list_csv.FromQmGrid(id(3 hDlg))" gets executed many times?
(and that the other variables get constantly re-declared?).
Is there a better way or can I leave the variable declarations at the position as shown my example?
#2
Declare anywhere, initialize under WM_INITDIALOG.

Quote:Does this mean for example "list_csv.FromQmGrid(id(3 hDlg))" gets executed many times?
In your code yes.

correct code:
Code:
Copy      Help
;;;variables declared here:
str- test1
str- test2
str- test4
ICsv- list_csv

sel message
,case WM_INITDIALOG
,list_csv=CreateCsv()
,list_csv.ColumnCount=5
,list_csv.Separator="*"
,list_csv.FromQmGrid(id(3 hDlg))

Quote:and that the other variables get constantly re-declared?
ICsv- list_csv ;;declaration. Declarations are not executed at run time.
list_csv=CreateCsv() ;;initialization. Executed every time. If under WM_INITDIALOG, executed once, because WM_INITDIALOG message is received once in a dialog.
#3
Now instead of thread variables can be used #sub with v attribute. Then the sub can use first function's variables. The dialog must not be non-modal.

Function Dialog171
Code:
Copy      Help
\Dialog_Editor

str test1
str test2
str test4
ICsv list_csv
list_csv=CreateCsv()
list_csv.ColumnCount=5
list_csv.Separator="*"

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040201 "*" "" "" ""

if(!ShowDialog(dd &sub.DlgProc 0)) ret


#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,list_csv.FromQmGrid(id(3 hDlg))
,case IDCANCEL
ret 1
#4
Thank you!!!


Forum Jump:


Users browsing this thread: 1 Guest(s)