- Daniel Vivier
- PowerBuilder
- Thursday, 18 October 2018 03:56 PM UTC
OK, here's a tough one! We have a need to detect, in an event in the main window, whether any response window is open. Currently the only reliable way we have found to do that is we wrote a function that lists every known response window and returns whether any of them are open, like:
if IsValid(w_response1) or IsValid(w_response2) ... or IsValid(w_responseN) then
return TRUE
else
return FALSE
end if
Obviously this is a maintenance concern, because you could forget to add a new window to the function we have that makes that determination.
We tried to think through a lot of other options but didn't come up with anything else that was both reliable and minimally invasive on our current codebase.
The reason we need this, by the way, is we have a file association that should trigger an action (importing a file) on the main window's menu. If the program is already open, a 2nd copy of it is opened by the file association, which then sends a message to the 1st copy's main window to give it the file name, then exits. The first copy gets that message, but it's only reasonable for it to proceed with the action if the user isn't busy doing something else in a response window! (The user is given a messagebox, telling them they can process the file later, if they are in fact in a response window.)
We considered a bunch of other approaches. One was reading lists of objects from the program's PBLs with LibraryDirectory(), but the problem there is that you can't call IsValid on a string that is the name of a window, in order to find out whether it's open - it has to be an actual window variable.
Another approach we considered was overriding Open and OpenWithParm with our own functions, that set a variable (say, gbNotInMainWindow), do the appropriate open, then on return from the open unset that variable. The problem with that is that if one response window opens a 2nd response window, on return from the 2nd one, gbNotInMainWindow will be set back to FALSE, when it should still be TRUE!
Does anybody have any better ideas for how to handle this that are not maintenance concerns like our current solution? Thanks.
Find Questions by Tag
Helpful?
If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.