|
|
Home » U++ Library support » U++ Widgets - General questions or Mixed problems » Strange behaviour of my modal dialog
Strange behaviour of my modal dialog [message #2804] |
Tue, 25 April 2006 22:57 |
|
forlano
Messages: 1187 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
I didn't know where to post this thread because I'm sure it is not a bug. Nevertheless i'm observing strange things, very strange, at least for me.
I've declared and defined a class, say Tournament. Then I've an instance TD of Tournament the which constructor set, for example
...
NAMETORNEO = "my Tournament";
...
Now I load a file and update NAMETORNEO with the value read from file, for example
...
TD.NAMETORNEO = "international";
...
I tested that TD.NAMETORNEO has been adjourned and now it is "international", no doubt about it please.
Now comes the strange things. I run a modal dialog to set a new tournament. The dialog is run by:
void VegaMain::NewTournament()
{ NewTournamentDlg newt;
//PromptOK( TD.NAMETORNEO + "1" ); // show "international"
newt.Run();
//PromptOK( TD.NAMETORNEO + "2" ); // show "international"
}
Here is some lines of the constructor of NewTournamentDlg :
NewTournamentDlg::NewTournamentDlg()
{ int i, j;
CtrlLayout(*this, "New Tournament");
editTourn <<= TD.NAMETORNEO;
PromptOK( TD.NAMETORNEO ); // TD.NAMETORNEO is again "my Tournament" !!!
...
I believed to set in editTourn the new value of TD.NAMETORNEO, i.e. "international", instead there is again the very old one, "my Tournament"! Why? After all newt born after I changed the value of TD.NAMETORNEO.
Perhaps it is normal but I need to synchronize NewTournamentDlg with the rest of the world. How to do?
I hope you have understood what I meant.
Luigi
[Updated on: Tue, 25 April 2006 22:58] Report message to a moderator
|
|
|
Re: Strange behaviour of my modal dialog [message #2807 is a reply to message #2804] |
Tue, 25 April 2006 23:10 |
|
mirek
Messages: 13980 Registered: November 2005
|
Ultimate Member |
|
|
Maybe I did not get it completely, but I guess the mistake you have done is that you think that "<<=" somewhat "binds" the variable with EditField (or other Ctrl).
However, that is not true - it is simple assignment, it sets the value of EditField, but the value of "TD.TOURNAMENT" is further unchanged by the EditField. If you need to have it changed, you have to perform "backward" assignment like
TD.NAMETONEO = ~newt.editTourn;
Of course, doing so for each variable would be boring, so U++ gives you better options.
First of all, you can consider whether you really need to have separate variable for tournament name. Sometimes you can simply use the dialog to store data and do not store to variable at all.
(Data are stored in widgets regardless it is "open").
Another option is to use "CtrlRetriever". This provides a kind of binding you perhaps have expected:
CtrlRetriever r;
r(newt.editTorneo, TD.TORNEO)
(newt.anotherField, TD.ANOTHER)
....
;
newt.Run();
r.Retrieve();
First past, using operator(), simply performs
ctrl <<= val;
and stores references to both to the list. Then Retrieve method goes through those references and performs
val = ~ctrl;
Primitive, but effective
Mirek
|
|
|
Re: Strange behaviour of my modal dialog [message #2808 is a reply to message #2807] |
Tue, 25 April 2006 23:33 |
|
forlano
Messages: 1187 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
luzr wrote on Tue, 25 April 2006 23:10 | Maybe I did not get it completely, but I guess the mistake you have done is that you think that "<<=" somewhat "binds" the variable with EditField (or other Ctrl).
However, that is not true - it is simple assignment, it sets the value of EditField, but the value of "TD.TOURNAMENT" is further unchanged by the EditField.
|
I was aware of it. I wanted put in EditField the value TD.TOURNAMENT and nothing else. I wanted to know the current value of TD.TOURNAMENT. Later another method will get what I've written in the EditField and then update TD.TOURNAMENT. My surprise is that TD.TOURNAMENT that finish in the EditField is the very old one. It seems the widget is not aware that TD.TOURNAMENT has already changed at some moment.
Quote: |
If you need to have it changed, you have to perform "backward" assignment like
TD.NAMETONEO = ~newt.editTourn;
Of course, doing so for each variable would be boring, so U++ gives you better options.
First of all, you can consider whether you really need to have separate variable for tournament name. Sometimes you can simply use the dialog to store data and do not store to variable at all.
(Data are stored in widgets regardless it is "open").
|
This is very interisting! I was not aware of it. In fact I get tired to use a parallel structure to store variables (I was afraid to loose them when the widget disappeared!)
Quote: | Another option is to use "CtrlRetriever". This provides a kind of binding you perhaps have expected:
CtrlRetriever r;
r(newt.editTorneo, TD.TORNEO)
(newt.anotherField, TD.ANOTHER)
....
;
newt.Run();
r.Retrieve();
First past, using operator(), simply performs
ctrl <<= val;
and stores references to both to the list. Then Retrieve method goes through those references and performs
val = ~ctrl;
Primitive, but effective
Mirek
|
I'm going to try it!
Luigi
|
|
|
|
|
Re: Strange behaviour of my modal dialog [message #2824 is a reply to message #2804] |
Wed, 26 April 2006 18:13 |
|
forlano
Messages: 1187 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
Hello,
I'm sorry to bother the forum once more with the same issue. Unfortunately I can't bypass this stupid problem that stopped me. I feel it is not a bug but the mistake it is not at all evident to me. I've prepared a minimalist example that shows what the problem is. They are 5 files very short. Who is interested can run the package attached (unzip in vegaTest). Here I show each file with the hope that the problem can be fixed on the fly.
File 1, is the *.h with the declaration of the two classes that are used by the program, one of them is a widget:
#include <CtrlLib/CtrlLib.h>
#define LAYOUTFILE <testVega/Vega.lay>
#include <CtrlCore/lay.h>
class NewTournamentDlg : public WithNewTournamentLayout<TopWindow> {
public:
typedef NewTournamentDlg CLASSNAME;
NewTournamentDlg();
~NewTournamentDlg() {;}
};
class RoundData {
public:
String NAMETORNEO;
RoundData();
~RoundData(){;}
};
// maybe the problem is the line below?
class RoundData TD; //is it seen in each *.cpp file? Is it a definition or a declaration?
File 2 is the definition of the method of the above widget. It put (it should put!) in an EditString the value TD.NAMETORNEO that has been set elsewhere:
#include "VegaMain.h"
NewTournamentDlg::NewTournamentDlg()
{ int i, j;
CtrlLayout(*this, "");
editTourn <<= TD.NAMETORNEO;
}
and this is the correspondent .lay file:
LAYOUT(NewTournamentLayout, 268, 92)
ITEM(EditString, editTourn, NotNull(true).LeftPosZ(16, 228).TopPosZ(36, 19))
END_LAYOUT
File 4, define the constructor of the non widget class:
#include "VegaMain.h"
RoundData::RoundData()
{ NAMETORNEO = "my torneo";
}
So "my torneo" is the name with which born an instance of the previous class. And now the last file, main.cpp, where happen strange things:
#include "VegaMain.h"
void NewMask()
{ TD.NAMETORNEO = "luigi";
NewTournamentDlg newt;
newt.Run(); //appear "my torneo"
PromptOK( TD.NAMETORNEO); //appear "luigi"
}
GUI_APP_MAIN
{ TopWindow w;
Button b;
w.Add(b);
b.SetLabel("push me").LeftPos(10, 100).TopPos(10, 30);
b.WhenAction = callback(NewMask);
w.Run();
}
As said in a previous post, after the previous:
TD.NAMETORNEO = "luigi";
I expect to see it inside the editstring of the widget because of its constructor. Instead appear "my torneo". It looks as TD is not seen by newt. How can I do visibile TD to newt? In C I could make TD global, but now?
What I am missing to do?
Thank you,
Luigi
-
Attachment: testVega.rar
(Size: 1.35KB, Downloaded 1562 times)
|
|
|
|
|
Goto Forum:
Current Time: Sat Jun 01 07:25:21 CEST 2024
Total time taken to generate the page: 0.02116 seconds
|
|
|