Click here to Skip to main content
16,005,209 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionproblem with radio button and UpdateData Pin
m.dietz3-Aug-07 4:13
m.dietz3-Aug-07 4:13 
AnswerRe: problem with radio button and UpdateData Pin
led mike3-Aug-07 4:52
led mike3-Aug-07 4:52 
GeneralRe: problem with radio button and UpdateData Pin
m.dietz5-Aug-07 20:11
m.dietz5-Aug-07 20:11 
GeneralRe: problem with radio button and UpdateData Pin
led mike6-Aug-07 5:29
led mike6-Aug-07 5:29 
AnswerRe: problem with radio button and UpdateData Pin
David Crow3-Aug-07 5:07
David Crow3-Aug-07 5:07 
GeneralRe: problem with radio button and UpdateData Pin
m.dietz5-Aug-07 20:28
m.dietz5-Aug-07 20:28 
GeneralRe: problem with radio button and UpdateData Pin
David Crow6-Aug-07 2:56
David Crow6-Aug-07 2:56 
GeneralRe: problem with radio button and UpdateData Pin
m.dietz6-Aug-07 20:43
m.dietz6-Aug-07 20:43 
OK, I read this article, and I disagree in more than one point.

The main reason why it says not to use UpdateData() is because this could mess up the original data. This can easily be avoided by keeping the original data stored in some variables/some structure, where it is read from by OnInitDialog() or some Init function you programmed yourself. Second I agree with the critic of NEVER using member variables of a function outside the class they are members of. Information handling between the dialog and the caller can be much easier achieved by giving a pointer to a memory location via a dialog function like InitData(). In this structure the caller writes its initialization data, OnInitDialog() reads from that structure to initialize the variables, in OnOK() the dialog writes back the result and the caller can read from the structure what he had in mind. This creates an usage of the dialog like
<br />
CMyDialog dlg;<br />
MYStructure str;<br />
str.Var1 = info1;<br />
str.Var2 = info2;<br />
dlg.MyInit(&str)<br />
dlg.DoModal();<br />
info1 = str.Var1;<br />
result = str.VarResult;<br />

In preserving the data in that structure you also always have a copy of your data for a Reset() which itself can call a function InitControls() shared with the OnInitDialog() routine. All intermediate data SHALL NOT BE STORED IN VARIABLES THE CALLER HAS ACCESS TO.

Second reason, why I disagree with that article: It says UpdateData would force you to keep an eye on your state and make sure it is always consistent and not a mixture of old and new data. That also can be avoided by keeping the separation between dialog data and display data. The only time a consistency check for display data has to be made is at the OnOK() event before writing the results back to the structure I used above. At every intermediate point it is not necessary to keep consistency, as all changes of UpdateData() only affects display data, not dialog data and when it is all checked at the OnOK() there still is time enough to tell the user what he did wrong (e.g "You can't choose 'dynamical selection' without selecting a rule.").

Third point of the article is the order in which the ON_CHANGE notifications happen. If there are some dependent data fields, the author says, then you get problems with setting the correct data of control B in accordance to the value of control A when the message is handled for control A. The author seemed to forget that it's YOU, the programmer, who knows about this dependencies, and YOU can set the values before calling UpdateData() making sure that the only work the ON_CHANGE event handler has to do is check that the data entered into control B is correct.

And to my humble opinon it's far easier to remember whether to use UpdateData with TRUE or FALSE than to remember each control and keep its value in an extra variable.

But this article does still not explain, why I get an ON_CLICK message for a control that is not clicked instead of an ON_CHANGE, which I can ignore if I want, and therefore, I still think this extra ON_CLICK message is neither wanted nor documented and something that is neither documented nor expected is a misbehaviour of software and as long as there are not really good reasons for this misbehaviour I see this as a caused by a bug.
AnswerRe: problem with radio button and UpdateData Pin
Hans Dietrich3-Aug-07 7:57
mentorHans Dietrich3-Aug-07 7:57 
GeneralRe: problem with radio button and UpdateData [modified] Pin
m.dietz5-Aug-07 20:20
m.dietz5-Aug-07 20:20 
QuestionRetrieve the length of an int Pin
Perspx3-Aug-07 4:02
Perspx3-Aug-07 4:02 
AnswerRe: Retrieve the length of an int Pin
Rage3-Aug-07 4:11
professionalRage3-Aug-07 4:11 
GeneralRe: Retrieve the length of an int Pin
Perspx3-Aug-07 4:14
Perspx3-Aug-07 4:14 
GeneralRe: Retrieve the length of an int Pin
David Crow3-Aug-07 4:22
David Crow3-Aug-07 4:22 
GeneralRe: Retrieve the length of an int Pin
LordMarv3-Aug-07 4:34
LordMarv3-Aug-07 4:34 
AnswerRe: Retrieve the length of an int Pin
David Crow3-Aug-07 4:12
David Crow3-Aug-07 4:12 
GeneralRe: Retrieve the length of an int Pin
Perspx3-Aug-07 4:15
Perspx3-Aug-07 4:15 
GeneralRe: Retrieve the length of an int Pin
David Crow3-Aug-07 4:23
David Crow3-Aug-07 4:23 
GeneralRe: Retrieve the length of an int Pin
Perspx3-Aug-07 4:26
Perspx3-Aug-07 4:26 
GeneralRe: Retrieve the length of an int Pin
CPallini3-Aug-07 4:27
mveCPallini3-Aug-07 4:27 
GeneralRe: Retrieve the length of an int Pin
David Crow3-Aug-07 5:01
David Crow3-Aug-07 5:01 
GeneralRe: Retrieve the length of an int Pin
CPallini3-Aug-07 4:26
mveCPallini3-Aug-07 4:26 
GeneralRe: Retrieve the length of an int Pin
Perspx3-Aug-07 4:28
Perspx3-Aug-07 4:28 
AnswerRe: Retrieve the length of an int [modified] Pin
m.dietz3-Aug-07 4:16
m.dietz3-Aug-07 4:16 
GeneralRe: Retrieve the length of an int Pin
CPallini3-Aug-07 4:52
mveCPallini3-Aug-07 4:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.