Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Passing value to smart dialogue
#1
I would welcome any advice on the following issue :

Function tempf13 calls twice function tempf12, which it is actually a smart dialogue :

Function tempf13
Code:
Copy      Help
tempf12 20
tempf12 22

Function tempf12
Code:
Copy      Help
;\Dialog_Editor
function int'i
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 208 66 "Dialog"
;3 Static 0x54000000 0x0 74 18 48 12 "Text"
;1 Button 0x54030001 0x4 86 44 48 14 "OK"
;2 Button 0x54030000 0x4 154 44 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040202 "*" "" "" ""

int- j=i
;j=i

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


#sub DlgProc
function# hDlg message wParam lParam
int- j
sel message
,case WM_INITDIALOG
,_s=F"{j}"
,_s.setwintext(id(3 hDlg))
,
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

The second time that tempf12 is called the new value of arg i is not passed correctly in the dialogue. Instead, if using the statement commented out, namely :

Quote:j=i


everything is OK.

I am wondering what is wrong in the first place.

Thanks in advance.
#2
To pass value to smart dialog, I often use 2 ways:
Method 1: using global variable
Function tempf12_with_global_var
Code:
Copy      Help
;\Dialog_Editor
function int'i
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 208 66 "Dialog"
;3 Static 0x54000000 0x0 74 18 48 12 "Text"
;1 Button 0x54030001 0x4 86 44 48 14 "OK"
;2 Button 0x54030000 0x4 154 44 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040202 "*" "" "" ""

int+ j=i
if(!ShowDialog(dd &sub.DlgProc 0)) ret

#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,_s=F"{j}"
,_s.setwintext(id(3 hDlg))
,
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
Method 2: use v param in sub function
Function tempf12_with_v_param
Code:
Copy      Help
;\Dialog_Editor
function int'i
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 208 66 "Dialog"
;3 Static 0x54000000 0x0 74 18 48 12 "Text"
;1 Button 0x54030001 0x4 86 44 48 14 "OK"
;2 Button 0x54030000 0x4 154 44 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040202 "*" "" "" ""

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

#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,_s=F"{i}"
,_s.setwintext(id(3 hDlg))
,
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

In your case, by trial and error I will do like this:
Function tempf12
Code:
Copy      Help
;\Dialog_Editor
function int'i
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 208 66 "Dialog"
;3 Static 0x54000000 0x0 74 18 48 12 "Text"
;1 Button 0x54030001 0x4 86 44 48 14 "OK"
;2 Button 0x54030000 0x4 154 44 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040202 "*" "" "" ""

int- j
j=i

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

#sub DlgProc
function# hDlg message wParam lParam
int- j
sel message
,case WM_INITDIALOG
,_s=F"{j}"
,_s.setwintext(id(3 hDlg))
,
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#3
QM thread variables behave like static variables in C/C++:
assignment is executed once if it is in declaration statement.

int- j=i ;;once in thread
j=i ;;everytime

---
To pass variables to a dialog procedure can be used:
thread variables,
#sub DlgProc v,
ShowDialog(... param) and DT_GetParam.
#4
Many thanks for your advices.


Forum Jump:


Users browsing this thread: 1 Guest(s)