Hi,
Is it possible to find out the owner of the current object ?
Owner of the object
- James Bott
- Posts: 4840
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: Owner of the object
I am not sure what you mean by "owner."
Did you mean local, private, or public?
Did you mean local, private, or public?
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Re: Owner of the object
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
Re: Owner of the object
Hi Natter:
Regards,
Code: Select all | Expand
#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)
//-----------------------------------------------//
Saludos,
Carlos Gallego
*** FWH-24.07, xHarbour 1.3.1 Build 20240624, Borland C++7.70, PellesC ***
Carlos Gallego
*** FWH-24.07, xHarbour 1.3.1 Build 20240624, Borland C++7.70, PellesC ***
Re: Owner of the object
Thanks for the help, Cgallegoa !
I need a TGet with a spinner and an arbitrary step of changes. I wrote it like this
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.
I need a TGet with a spinner and an arbitrary step of changes. I wrote it like this
Code: Select all | Expand
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})
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.
- Enrico Maria Giordano
- Posts: 8728
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: Owner of the object
hi Natter,
try different Parent as Parameter Oself
perhaps this Method can helpNatter wrote:Here I need the owner of the oVScroll object.
Code: Select all | Expand
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
greeting,
Jimmy
Jimmy
Re: Owner of the object
Thank you all ! I've already done
Code: Select all | Expand
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))})