FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Owner of the object
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Owner of the object
Posted: Wed Mar 01, 2023 12:03 PM

Hi,

Is it possible to find out the owner of the current object ?

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Owner of the object
Posted: Wed Mar 01, 2023 03: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
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Owner of the object
Posted: Wed Mar 01, 2023 07: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

Posts: 514
Joined: Sun Oct 16, 2005 03:32 AM
Re: Owner of the object
Posted: Wed Mar 01, 2023 08:06 PM
Hi Natter:
Code (fw): Select all Collapse
#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-25.12, xHarbour 1.3.1 Build 20241008, Borland C++7.70, PellesC, ADS 11.1***

Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Owner of the object
Posted: Wed Mar 01, 2023 09: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 (fw): Select all Collapse
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:
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: Owner of the object
Posted: 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 (fw): Select all Collapse
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
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Owner of the object
Posted: Thu Mar 02, 2023 10:26 AM
Thank you all ! I've already done
Code (fw): Select all Collapse
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))})

Continue the discussion