1. Pau Haro
  2. PowerBuilder
  3. Wednesday, 8 July 2020 12:00 PM UTC

Hello, 

 

Im trying to know what object of my window have the focus. I looked for it on google but it don't works for me.

 

I'll be gratefull if someone can help me.

 

I let the code that I found on google down below.

 

GraphicObject which_control

which_control = GetFocus() 

Accepted Answer
John Fauss Accepted Answer Pending Moderation
  1. Wednesday, 8 July 2020 13:49 PM UTC
  2. PowerBuilder
  3. # Permalink

Greetings, Pau - 

First, what version/release/build of PowerBuilder are you using?

Second, from what object/event/function are you invoking the GetFocus PowerScript function?

The function works fine for me. I created an unmapped user event in a sheet window named ue_GetFocus that takes no arguments and returns no value, and placed this code in it:

String ls_classname
GraphicObject lgo_test

lgo_test = GetFocus()

If IsValid(lgo_test) Then
   ls_classname = lgo_test.ClassName()
   MessageBox('GetFocus Test','The object named "'+ls_classname+'" has input focus.')
Else
   MessageBox('GetFocus Test','The GraphicObject reference is not valid.')
End If

In a new "GetFocus Test" menu item in my MDI test app, I placed the following:

Window lw_sheet

lw_sheet = gnv_app.of_GetFrame().GetActiveSheet()
If IsValid(lw_sheet) Then
   lw_sheet.Event Dynamic ue_GetFocus()
Else
   MessageBox('GetFocus Test','There is no active sheet window.')
End If

When the sheet window is opened, I navigate to any control in the window via the tab key, then click on the "GetFocus Test" menu item, and the name of the control that has input focus is displayed. For example:

I'm using PB 2017 R2.

HTH. John

Comment
  1. Pau Haro
  2. Wednesday, 8 July 2020 14:18 PM UTC
Hi John,

Your code is working for me, I don't know what I was doing wrong but It's ok.

Thanks greetings.
  1. Helpful
There are no comments made yet.
Pau Haro Accepted Answer Pending Moderation
  1. Wednesday, 8 July 2020 13:27 PM UTC
  2. PowerBuilder
  3. # 1

Hi Pau,

GetFocus() is the correct function. It returns the object that currently has focus in your application.

Please specify why it is not working for you?

 

Hello René,

GetFocus function returns me a null GraphicObject instead of returning the item that have the focus.

Comment
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Wednesday, 8 July 2020 12:37 PM UTC
  2. PowerBuilder
  3. # 2

Hi Pau,

GetFocus() is the correct function. It returns the object that currently has focus in your application.

Please specify why it is not working for you?

Comment
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.