1. Troy Cowan
  2. PowerBuilder
  3. Tuesday, 30 July 2024 14:47 PM UTC

I have a situation where I have two windows open; Window A and Window B. Window A has the focus.

I click a button on Window A, and in the click event handler it calls GetFileSaveName(). Even if nothing else happens after that (I commented out all the other code that uses the return from GetFileSaveName), the focus changes to Window B. I can't figure out why this is happening. 

Somehow this doesn't happen all the time. Sometimes the focus stays on Window A. I haven't figured out if there is a pattern to this, it just seems completely random. 

If I put Parent.Post SetFocus() in the code after the call to GetFileSaveName the focus seems to stay on Window A as desired. I assume it could be setting focus to Window B and then back to Window A. 

Any advice on how to troubleshoot this would be great. 

John Fauss Accepted Answer Pending Moderation
  1. Tuesday, 30 July 2024 15:22 PM UTC
  2. PowerBuilder
  3. # 1

Hi, Troy -

A little more information, if you please:

1. What version, release, build of PB?

2. Are you using the new TabbedView interface?

3. Is this an MDI app and are Windows A & B sheet windows? If not, what type(s) of windows are they?

4. Is the app written using an object framework, such as STD or PFC?

5. Do you see this behavior when running the app from the IDE, from an EXE, or both?

6. What operating environment is the app running on (desktop, remote desktop, Citrix, etc.)?

7. Aside from posting a SetFocus to address the symptom of the issue, what have you tried to diagnose the cause of the problem?

Best regards, John

Comment
There are no comments made yet.
Troy Cowan Accepted Answer Pending Moderation
  1. Tuesday, 30 July 2024 17:29 PM UTC
  2. PowerBuilder
  3. # 2

What version, release, build of PB?

2021 build 1506

Are you using the new TabbedView interface?

No

Is this an MDI app and are Windows A & B sheet windows? If not, what type(s) of windows are they?

It is an MDI app. Both windows are sheet windows.

Is the app written using an object framework, such as STD or PFC?

            No

Do you see this behavior when running the app from the IDE, from an EXE, or both?

Both

What operating environment is the app running on (desktop, remote desktop, Citrix, etc.)?

Desktop (Windows 10 Enterprise)

Aside from posting a SetFocus to address the symptom of the issue, what have you tried to diagnose the cause of the problem?

Not much. Not sure where to go from here, hence the posting of the question. I have been able to simplify the code in the event handler down to just the bare minimum that will causes the problem to happen: 

string ls_path, ls_filename
integer li_ret
li_ret = GetFileSaveName("Save File As",ls_path,ls_filename,"xlsx","Excel Files (*.XLSX),*.XLSX")

It doesn't matter if you pick a file or just click cancel on the file picker dialog, the problem happens either way. 

BTW, the button is just a straight CommandButton, so there shouldn’t be anything happening “under the hood”.

Comment
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Tuesday, 30 July 2024 18:29 PM UTC
  2. PowerBuilder
  3. # 3

I threw together a bare-bones test app in PB 2021 Build 1509...

...and it works as expected.

My only suggestion is to step through the execution of the app from the IDE using the Debugger, beginning at the GetFileSaveName PowerScript function call and see what it does.

Comment
  1. Troy Cowan
  2. Wednesday, 31 July 2024 12:12 PM UTC
Yes, I never really suspected a bug in Powerbuilder itself - much more likely that there's something in our code we need to fix. My request was more of a "how do I troubleshoot this kind of thing" kind of question. I certainly can put a breakpoint in my Click event handler, but I've stripped it down so much there isn't really anything in there to look at.
  1. Helpful
  1. Roland Smith
  2. Wednesday, 31 July 2024 12:52 PM UTC
Debugger activating is going to trigger a change in focus.



I like to use Debug Viewer. Add this external function:



Subroutine DebugMsg ( string lpOutputString ) Library "kernel32.dll" Alias For "OutputDebugStringW"



Then add calls to your code:



DebugMsg("Process starting")



You can get the Debug Viewer app here:



https://learn.microsoft.com/en-us/sysinternals/downloads/debugview

  1. Helpful 2
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.