Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reset
#1
I have a dialog with some controls:

case 19
_s=""
_s.setwintext(id(3 hDlg))
_s.setwintext(id(4 hDlg))
_s.setwintext(id(5 hDlg))
_s.setwintext(id(10 hDlg))
_s.setwintext(id(15 hDlg))
_s.setwintext(id(16 hDlg))
_s.setwintext(id(17 hDlg))
_s.setwintext(id(18 hDlg))
estan=""
noestan=""

Is there any way to reset controls and variables with one function?
or reset int variables;str variables...?
#2
To reset controls to default values, can be used DT_SetControls, but it must be slightly modified. If you don't want to wait for next QM version, use its copy DT_SetControls2:

Code:
Copy      Help
;/
function# hDlg [lParam]

;This function must be called from dialog procedure.
;Sets controls data.
;Called by DT_Init when initializing dialog.


;You can also call this function from dialog procedure, when you
;need to set controls again. Then lParam must be omitted or 0.



opt end 1
__DIALOG* d
if(lParam) SetProp(hDlg "dialogdata" lParam); d=+lParam
else d=+GetProp(hDlg "dialogdata"); if(!d) ret

str* p=d.pdata; if(!p) ret
str cls li
int i j k h n stl lh handle

for i 0 1000000
,j=findt(p[0] i " "); if(j<0) break
,if(!isdigit(p[0][j])) end "invalid first string" 5
,j=val((p[0]+j))
,if(j) h=id(j hDlg); if(!h) end "dialog doesn't have control with id %i" 5 j
,k+1
,str& s=p[k]
,if(s.len>s.nc or s.len<0 or (s.lpstr and IsBadWritePtr(s.lpstr 1)) or s.len!=len(s)) end "invalid str array" 5
,if(!s.lpstr and lParam) continue
,
,if(j=0)
,,if(lParam) s.setwintext(hDlg)
,,continue
,
,sel(cls.getwinclass(h) 1)
,,case "Button"
,,stl=GetWinStyle(h)&15
,,if(stl>1 and stl<7 or stl=9)
,,,if(val(s)) CheckDlgButton(hDlg j 1)
,,,else if(!lParam) CheckDlgButton(hDlg j 0)
,,,continue
,,,
,,case "ListBox"
,,stl=GetWinStyle(h)&LBS_MULTIPLESEL
,,TO_CBFill h s iif(stl 2 1)
,,continue
,,
,,case "ComboBox"
,,TO_CBFill h s
,,continue
,,
,,case "Static"
,,if(!lParam) continue
,,sel(GetWinStyle(h)&31)
,,,case SS_ICON
,,,int large=s[0]='&'
,,,handle=GetIcon(s+large large); if(handle=0) continue
,,,SendMessage(h STM_SETICON handle 0)
,,,lh=d.handles._len; d.handles._resize
,,,d.handles[lh].handle=handle; d.handles[lh].flags=1
,,,continue
,,,case SS_BITMAP
,,,handle=LoadImage(0 s.expandpath IMAGE_BITMAP 0 0 LR_LOADFROMFILE); if(handle=0) continue
,,,SendMessage(h STM_SETIMAGE IMAGE_BITMAP handle)
,,,lh=d.handles._len; d.handles._resize
,,,d.handles[lh].handle=handle; d.handles[lh].flags=2
,,,continue
,,,
,,case "RichEdit20A"
,,SendMessage h EM_LIMITTEXT 0x7FFFFFFE 0
,,if(s.beg("&") and RichEditLoad(h s+1)) continue
,,
,s.setwintext(h)

ret 1

After upgrading QM you should stop using DT_SetControls2, and use DT_SetControls, because it may be extended in the future.

Other way - temporarily remove read-only property from System folder (not file), replace DT_SetControls text with this new text, and export/overwrite System folder.
_______________________

Sample dialog dialog_reset:
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3 4"
str e3 e4
e3="abc"
if(!ShowDialog("dialog_reset" &dialog_reset &controls)) ret

;BEGIN DIALOG
;0 "" 0x10C80A44 0x100 0 0 223 135 "Form"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 Edit 0x54030080 0x200 12 10 96 14 ""
;4 Edit 0x54030080 0x200 12 32 96 14 ""
;5 Button 0x54032000 0x0 12 52 48 14 "Reset"
;END DIALOG
;DIALOG EDITOR: "" 0x2010800 "*" ""


ret
;messages
sel message
,case WM_INITDIALOG DT_Init(hDlg lParam); ret 1
,case WM_DESTROY DT_DeleteData(hDlg)
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 5
,DT_SetControls2 hDlg
,case IDOK DT_Ok hDlg
,case IDCANCEL DT_Cancel hDlg
ret 1

_____________________

I also have to say that dialog variables are not updated whenever something is changed in the dialog. To populate variables without closing the dialog, call DT_GetControls. It is called by DT_Ok, which also closes the dialog.
#3
Thanks.
When the next QM version?
#4
Better don't ask, I always break promises.
#5
and for reset variables?
#6
While in dialog proc, variables have default values, unless you call DT_GetControls.

Here is how all works:
1. When opening dialog, is called dialog procedure. Then message is WM_INITDIALOG. As you see, then is called DT_Init, which calls DT_SetControls, which initializes controls with interpreted values of dialog variables.
2. While dialog is open, dialog variables are not touched. That is, you don't have to reset variables. If you call DT_SetControls2, controls are reset to default values because variables have default values. But if you before called DT_GetControls, then variables are already changed, and if you want to reset all, reset each variable and then call DT_SetControls2.
3. When closing dialog with OK, is called dialog procedure. Then message is WM_COMMAND, and wParam is IDOK. Is called DT_Ok, which calls DT_GetControls, which collects values of controls and populates variables.
#7
Ok.
but in any other macro...

str a b c d
a="test1"
b="test2"
c="test3"
d="test4"


reset a b c d ?
#8
What is your question?


Attached Files Image(s)
   
#9
How reset variables with one function.
#10
In QM, when you declare several local variables of same type, they are located as array, so this works:

Code:
Copy      Help
str a b
str c d
a="test1"
b="test2"
c="test3"
d="test4"

str* p=&a
int i
for(i 0 4) p[i].all
#11
Perfect. Thanks.
In the next version you can add ResetAllVariables function...
#12
I tried to create the function ResetAllVariables without success.
can you help me?
#13
Code:
Copy      Help
;/
function str&first num

;Clears specified number of str variables.
;No other variables must be declared between these.


;first - first variable
;num - number of variables


;EXAMPLE
;str a b
;str c d
;a="a"
;b="b"
;c="c"
;d="d"
;;...
;ResetStrVariables a 4



int i
str* p=&first
for(i 0 num) p[i].all

To reset variables of other types, create similar functions for each type.
#14
Thanks for all.


Forum Jump:


Users browsing this thread: 1 Guest(s)