I have a window in which there is a button that, if clicked, will open a second document window. Also in the main window is a second button that, when clicked will retrieve some data externally (via an HTTP socket) and update the main window’s display. At the same time, if the second document window is open data in that window should update. I have used
For i As Integer = WindowCount - 1 DownTo 0
If Window(i).Title = "SecondWindow" then
to detect if the second window is open and update it. I have code in a method in the second window to handle the updating of the data in that window.
My concern is that I’m on Windows 10 and UpdateNow is not really intended for Windows (the LR says is does nothing). Yet it works as I want it to. But I feel that I’m on thin ground and aren’t really doing things the right way. Unfortunately, I haven’t been able to figure out a better or correct way to accomplish it. Instead of Window(i).UpdateNow, I tried SecondWindow.DoAnUpdate but I keep getting an error
Static reference to instance method: call this on an instance if class SecondWindow.SecondWindow
So what would be the correct way to tell a (non-implicit Instance) window to update itself? I would really not have to close and re-open the window each time the data in the main window updates.
Of course, if using UpdateNow in this way is ok, I’m good with leaving it.
So looking at the docs, it’s meant to force the window buffer forwards on OS X only. It claims that it shouldn’t do anything on Windows or Linux. So I would assume that this is a bug and would advise against relying on a bug.
I’m guessing what you want is actually window.refresh
Given that your window is an implicitInstance, you could add a shared property to it called “isOpen”, when the window opens, it sets this to true, when the window closes, False. Then at any point in code you can use “if secondWindow.isOpen then”.
[quote=257863:@Tim Hare]Cast Window(i) to the window type and you can call any of its methods.
if Window(i) ISA SecondWindow then
Thanks, Tim. I knew I was doing something wrong but couldn’t seem to hit on the right way.
[quote=257865:@Sam Rowlands]I’m guessing what you want is actually window.refresh
Given that your window is an implicitInstance, you could add a shared property to it called “isOpen”, when the window opens, it sets this to true, when the window closes, False. Then at any point in code you can use “if secondWindow.isOpen then”.[/quote]
Sam, a window Refresh would just redraw the window’s contents as they were. It wouldn’t cause the data update that I need to have happen. And the second is not an implicit instance type since I want it up only when the user asks for it. Once it is shown, it needs to update when the user updates the data in the main window. Tim’s method is the right approach for my application.
But neither the Refresh nor the Invalidate will cause the window to process any methods belonging to that window, will they? Won’t it simply be redrawn as determined by the original contents and whatever may be coded into the various intrinsics for drawing the window? For example, if there is a listbox in the invalidated area the various cell painting event handlers may be called, or the contents of a canvas may be changed. But neither the Invalidate nor the Refresh will call the method that initiates the changing of the listbox cell values or canvas’ contents. That is why I needed to call the window’s method before redrawing occurs.
No it wont it will just mark the window as needing to redraw
Refresh and UpdateNow really dont do anything more they just say “do it NOW!” - thereby potentially making them slow things down
IF you need to call a method on window that refreshes data then you should add a method to the window as Tim outlined so many posts ago and then also call Invalidate so that window DOES get a redrawn with the new data