exchange information between windows

Hi,
for the following issue I have a solution, but I think that it is no professional solution, so I need to know if there is another better solution.
I have 3 window: win1, win2 and win3. I can show win3 from win1 OR from win2. (if win1 is open than win2 is closed and viceversa).
When win3 is open I can write a value on it (es. in textfield) and when press OK button this value is written on win1 or in win2.
Now, my solution is: I have a global variable num_win as integer. num_win is = 1 if there is open win1 and = 2 if there is open win2.
So I write the value in win1 if num_win = 1 and in win2 id num_win = 2.
Best Regards
Fabio

[quote=165974:@fabio stranieri]for the following issue I have a solution, but I think that it is no professional solution, so I need to know if there is another better solution.
I have 3 window: win1, win2 and win3. I can show win3 from win1 OR from win2. (if win1 is open than win2 is closed and viceversa).
When win3 is open I can write a value on it (es. in textfield) and when press OK button this value is written on win1 or in win2.
Now, my solution is: I have a global variable num_win as integer. num_win is = 1 if there is open win1 and = 2 if there is open win2.
So I write the value in win1 if num_win = 1 and in win2 id num_win = 2. [/quote]

If what you want to do is keep track of which windows are opened, and it works for you, then that is fine.

Alternatively, you could look into the Window method that enables you to know which windows are currently open :
http://documentation.xojo.com/index.php/Window_Method

create a property in win3 such parentWindow as window
when you show the win3 from win1 you set the parentWindow = win1
when you show the win3 from win2 you set the parentWindow = win2

after that, from win3 you just call the text property of the control with parentWindow.mycontrol.Text

more “object friendly” than global variables.

Thank you very much for the response. I’ve tried jean-yves pochez solution, but when I call parentWindow.mycontrol.Text it goes in error with: “this item does not exist”

parentWindow.lbl_Ind_Tag(num_tag).text = "MB"

Best Regards
Fabio

sorry you have to subclass window with mywindow
then win1 and win2 must be a subclass of mywindow
then mywindow must have a method that sets the text where it has to be
and you call that method from win3

easy!! :frowning:

[quote=165987:@jean-yves pochez]sorry you have to subclass window with mywindow
then win1 and win2 must be a subclass of mywindow
then mywindow must have a method that sets the text where it has to be
and you call that method from win3[/quote]
You could also use an interface. The interface would have a single method for setting the text, and then apply the interface to each window. When you need to address one of these windows, you would use:

if window1 IsA myInterface Then MyInterface(window1).setText("hello") End If

Interface is a much better solution, IMO. Couple it with Window() for best encapsulation (no need for a variable to point to the window).

for i = 1 to WindowCount
    if window(i) isa myInterface then
       myInterface(window(i)).setText("hello")
   end
next

I wouldnt do an interface for 2 windows, but yes this is a better implementation !

I would.

[quote=166090:@Tim Hare]Interface is a much better solution, IMO. Couple it with Window() for best encapsulation (no need for a variable to point to the window).

for i = 1 to WindowCount if window(i) isa myInterface then myInterface(window(i)).setText("hello") end next [/quote]
Wouldn’t it have to be

for i = 1 to WindowCount -1

[quote=166195:@Markus Winter]Wouldn’t it have to be

for i = 1 to WindowCount -1

Of course. Good catch.