Owner of the object

Owner of the object

Postby Natter » Wed Mar 01, 2023 12:03 pm

Hi,

Is it possible to find out the owner of the current object ?
Natter
 
Posts: 1222
Joined: Mon May 14, 2007 9:49 am

Re: Owner of the object

Postby James Bott » Wed Mar 01, 2023 3:45 pm

I am not sure what you mean by "owner."
Did you mean local, private, or public?
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Owner of the object

Postby Natter » Wed Mar 01, 2023 7:00 pm

For example, the control is located on the window. So this window is the owner of this control. From the control code block, I want to contact the owner
Natter
 
Posts: 1222
Joined: Mon May 14, 2007 9:49 am

Re: Owner of the object

Postby Cgallegoa » Wed Mar 01, 2023 8:06 pm

Hi Natter:
Code: Select all  Expand view  RUN
#include "FiveWin.ch"

STATIC oWnd
STATIC oSay1, oSay2, cTit1:="", cTit2:=""

Function Main()
   LOCAL oBtn1, oBtn2, oChk1, lChk1 := .F., oChk2, lChk2 := .F., aResp := {}
     LOCAL oGet1, cTxt1 := "Click on get's button"
   LOCAL oFont1, oRad, nValue := 1, i := 1
     DEFINE FONT oFont1 NAME "Verdana" SIZE 0,-16
   DEFINE WINDOW oWnd TITLE "Owner of the object"

      @  20, 40 BTNBMP oBtn1 PROMPT "Show Owner" OF oWnd PIXEL ACTION ShowResp2() SIZE 150,30 FLAT
     
      @  90, 40 CHECKBOX oChk1 VAR lChk1 OF oWnd PIXEL SIZE 100,15  ;
         ON CHANGE ShowResp2()

      @ 150, 40 RADIO oRad VAR nValue ;
         ITEMS "&One", "&Two", "T&hree" _3D OF oWnd SIZE 150, 21 PIXEL;
         ON CHANGE ShowResp2();

      @  80,220 SAY "Owner:" OF oWnd PIXEL FONT oFont1 SIZE 90,25
      @  80,310 SAY oSay1 VAR cTit1 OF oWnd PIXEL FONT oFont1 SIZE 150,25
      @ 110,220 SAY "Curr.Obj:" OF oWnd PIXEL FONT oFont1 SIZE 90,25
      @ 110,310 SAY oSay2 VAR cTit2 OF oWnd PIXEL FONT oFont1 SIZE 150,25

   for i:= 1 TO Len(oRad:aItems)
       oRad:aItems[ i ]:bGotFocus := {|| ShowResp2() }
   next
   
   ACTIVATE WINDOW oWnd CENTERED // on init ShowResp2() // xBrowse(oRad)
   RELEASE FONT oFont1
Return(NIL)
//-----------------------------------------------//

Function ShowResp1()
   LOCAL aResp := {}
   AADD(aResp,{FindOwnerObj(),MiReadVar1()} )
   oSay1:SetText(aResp[1,1]:ClassName())
   oSay2:SetText(aResp[1,2]:ClassName())
   oWnd:Update()
Return(NIL)
//-----------------------------------------------//

Function ShowResp2()
   LOCAL aResp := {}
   AADD(aResp,{FindOwnerObj(),CurrentCrtl()} )
   oSay1:SetText(aResp[1,1]:ClassName())
   oSay2:SetText(aResp[1,2]:ClassName())
   oWnd:Update()
Return(NIL)
//-----------------------------------------------//

Function FindOwnerObj()   // Para encontrar el Objeto del Diálogo activo
LOCAL aWindows:=GetAllWin(), ii:=1, oDlg
LOCAL nId:=GetActiveWindow()       // Tengo el Handle
for ii=1 to len(aWindows)
    oDlg := aWindows[ii]
    IF VALTYPE(ODLG)=="O"
       if oDlg:oWnd<>Nil
          if oDlg:oWnd:hWnd==nId
             oDlg:=oDlg:oWnd
             ii:=len(aWindows)
          endif
       ENDIF
    ENDIF
next
return(oDlg)
//-----------------------------------------------//

Function CurrentCrtl()
LOCAL oDlg, hFoc, oControl, nPos:=0, iii:=1
oDlg := FindOwnerObj()    // Devuelve el Diálogo actual
hFoc := GetFocus()  // Devuelve el control que tiene el foco
nPos := ASCAN(oDlg:aControls,{|o|o:hWnd==hFoc})
IF ( nPos != 0 )
   oControl := oDlg:aControls[nPos]
endif
Return(oControl)
//-----------------------------------------------//

Function MiReadVar1()
LOCAL oDlg, hFoc, oControl, nPos:=0, iii:=1
oDlg := FindOwnerObj()    // Devuelve el Diálogo actual
hFoc := GetFocus()        // Devuelve el control que tiene el foco
nPos := ASCAN(oDlg:aControls,{|o|o:hWnd==hFoc})
IF ( nPos != 0 )
     While .T.
        if nPos-iii=1
           oControl:=ReadVar()
           Exit
        endif
        if oDlg:aControls[nPos-iif(nPos<=1,0,iii)]:ClassName()=="TGET"
           oControl := oDlg:aControls[nPos-iif(nPos<=1,0,iii)]
           exit
        else
           iii++
        endif
     enddo
ENDIF
Return(oControl)
//-----------------------------------------------//
 
Regards,
Saludos,

Carlos Gallego

*** FWH-24.07, xHarbour 1.3.1 Build 20240624, Borland C++7.70, PellesC ***
Cgallegoa
 
Posts: 494
Joined: Sun Oct 16, 2005 3:32 am
Location: Quito - Ecuador

Re: Owner of the object

Postby Natter » Wed Mar 01, 2023 9:07 pm

Thanks for the help, Cgallegoa !
I need a TGet with a spinner and an arbitrary step of changes. I wrote it like this
Code: Select all  Expand view  RUN
TGet():New(2, 2, GenLocalBlock( nGet ), oDlg, ;
          100,, "9.999",,,,,,, .T.,,,,,,,,,,, .T., ;
          {||self:=HB_QSelf(),::cText(val(::GetText())+0.05)}, ;
          {||self:=HB_QSelf(),::cText(val(::cText())-0.05)}, ;
          {||self:=HB_QSelf(),val(::cText())>=0.6}, ;
          {||self:=HB_QSelf(),val(::cText())<=1})


However, this will not work because self is an oVScrolls object (see method :Spinner).
Here I need the owner of the oVScroll object.

Of course, this problem can be solved by writing your own version of the TGet class or creating your own function instead of the :Spinner method, but this is more interesting. :wink:
Natter
 
Posts: 1222
Joined: Mon May 14, 2007 9:49 am


Re: Owner of the object

Postby Jimmy » Thu Mar 02, 2023 10:00 am

hi Natter,
Natter wrote:Here I need the owner of the oVScroll object.

perhaps this Method can help
Code: Select all  Expand view  RUN
METHOD GetScrollbarObj( oSelf, lVScroll ) CLASS TGrid
LOCAL oObj, cTitle := ""
LOCAL hWnd := 0

   DEFAULT oSelf := SELF
   DEFAULT lVScroll := .T.

   IF lVScroll
      cTitle := "oVScroll"
      IF __objHasData( oSelf, "oVScroll" )
         oObj := oSelf:oVScroll             // VERTICAL
      ELSE
         MsgInfo( "no oVScroll",cTitle )
      ENDIF
   ELSE
      cTitle := "oHScroll"
      IF __objHasData( oSelf, "oHScroll" )
         oObj := oSelf:oHScroll             // HORIZONTAL
      ELSE
         MsgInfo( "no oHScroll" ,cTitle)
      ENDIF
   ENDIF

   IF VALTYPE( oObj ) = "O"
      IF __objHasData( oObj, "hWnd" )
         hWnd := oObj:hWnd
      ELSE
         MsgInfo( "no oObj:hWnd" ,cTitle)
      ENDIF
   ELSE
      MsgInfo( "Object " + hb_valToExp(oObj),cTitle)
   ENDIF

RETURN hWnd

try different Parent as Parameter Oself
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Owner of the object

Postby Natter » Thu Mar 02, 2023 10:26 am

Thank you all ! I've already done
Code: Select all  Expand view  RUN
TGet():New(2, 2, GenLocalBlock( nGet ), oDlg, ;
       100,, "9.999",,,,,,, .T.,,,,,,,,,,, .T., ;
       {||self:=HB_QSelf():oWnd,iif(::value+0.05>1,.T.,::cText(::value+0.05))}, ;
       {||self:=HB_QSelf():oWnd,iif(::value-0.05<0.59,.T.,::cText(::value-0.05))})
Natter
 
Posts: 1222
Joined: Mon May 14, 2007 9:49 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 108 guests