Author | Topic: Property from activeX in a Class | |
---|---|---|
AUGE_OHR | Property from activeX in a Class on Mon, 23 Feb 2009 23:12:20 +0100 hi, lets say i have a activeX with Property :BackColor. this works: oXbp := XbpActiveXControl():new( oParent, oOwner, aPos,aSize) oXbp:CLSID := ... oXbp:License := ... oXbp:create() oXbp:BackColor := myColor now i write a Class for it CLASS HX_Button FROM XbpActiveXControl EXPORTED: VAR HX_PushButton METHOD Init() METHOD Create() ENDCLASS METHOD HX_Button:Init(oParent, oOwner, aPos, aSize, aPP, lVisible) ::HX_PushButton := XbpActiveXControl():new( oParent, oOwner, aPos,aSize) ::HX_PushButton:CLSID := ... ::HX_PushButton:License := ... RETURN self METHOD HX_Button:Create(oParent, oOwner, aPos, aSize, aPP, lVisible) ::HX_PushButton:Create() RETURN self this does NOT work: oXbp := HX_Button():New(...):create() oXbp:BackColor := myColor <- CRASH here ... why ??? i have to use oXbp:HX_PushButton:BackColor := myColor or VAR myProperty ASSIGN METHOD _BackColor() VAR BackColor is this a BUG or a Futures ? greetings by OHR Jimmy | |
AUGE_OHR | Re: Property from activeX in a Class on Mon, 23 Feb 2009 23:21:28 +0100 > VAR myProperty > ASSIGN METHOD _BackColor() VAR BackColor is VAR BackColor ASSIGN METHOD _BackColor() VAR BackColor METHOD HX_Button:_BackColor(xValue) Gets or sets the background LOCAL xRet IF PCOUNT() > 0 IF VALTYPE(xValue) = "N" ULONG ::HX_PushButton:BackColor := (AutomationTranslateColor(xValue,.F.) ) ENDIF xRet := ::HX_PushButton:BackColor ENDIF RETURN xRet greetings by OHR Jimmy | |
Sebastiaan | Re: Property from activeX in a Class on Wed, 25 Feb 2009 09:12:42 +0100 Hi, This is not a bug and not a feature. Just normal behavior. You create an object HX_PushButton as a new member of your class. Property BackColor is a member of this new object and not your HX_Button. So I wouldn't expect anything else. Why don't you just make something like this. CLASS HX_Button FROM XbpActiveXControl EXPORTED: METHOD Init() METHOD Create() ENDCLASS METHOD HX_Button:Init(oParent, oOwner, aPos, aSize, aPP, lVisible) ::XbpActiveXControl:Init(oParent, oOwner, aPos, aSize, aPP, lVisible) RETURN METHOD HX_Button:Create(oParent, oOwner, aPos, aSize, aPP, lVisible) ::XbpActiveXControl:Create(oParent, oOwner, aPos, aSize, aPP, lVisible) RETURN Your class is already derived from XbpActiveXControl. In your example you basically create two instances of XbpActiveXControl. Secondly in your method HX_Button:_BackColor I think you meant to put xRet := ::HX_PushButton:BackColor after the ENDIF, now the method doesn't return the value unless you set a new value. Sebastiaan | |
AUGE_OHR | Re: Property from activeX in a Class on Wed, 25 Feb 2009 22:01:40 +0100 hi, > This is not a bug and not a feature. > Just normal behavior. > You create an object HX_PushButton as a new member of your class. Yes > Property BackColor is a member of this new object and not your HX_Button. No > Why don't you just make something like this. > > CLASS HX_Button FROM XbpActiveXControl > EXPORTED: > METHOD Init() > METHOD Create() > ENDCLASS > > METHOD HX_Button:Init(oParent, oOwner, aPos, aSize, aPP, lVisible) > ::XbpActiveXControl:Init(oParent, oOwner, aPos, aSize, aPP, lVisible) > RETURN > > METHOD HX_Button:Create(oParent, oOwner, aPos, aSize, aPP, lVisible) > ::XbpActiveXControl:Create(oParent, oOwner, aPos, aSize, aPP, lVisible) > RETURN there is no differens if i have "::HX_Button :=" before both Lines > Your class is already derived from XbpActiveXControl. In your example you > basically create two instances of XbpActiveXControl. No, why do you think that ? using ":=" does not meen a new instance. > Secondly in your method > > HX_Button:_BackColor > > I think you meant to put > xRet := ::HX_PushButton:BackColor > after the ENDIF, >now the method doesn't return the value unless you set a new value. No every Methode is Read/Write. again all works fine but i want to know what is the Difference in : ****************************************************************************************** oXpb := XbpActiveXControl:New(oParent, oOwner, aPos, aSize, aPP, lVisible) oXbp:Create() oXbp:SetProperty("myProperty",xValue) -> this works ****************************************************************************************** CLASS myClass FROM XbpActiveXControl ... oXpb := myClass:New(oParent, oOwner, aPos, aSize, aPP, lVisible) oXbp:Create() oXbp:SetProperty("myProperty",xValue) -> this dos NOT work !!! ****************************************************************************************** i have to use ASSIGN METHODE to make it work, WHY ? greetings by OHR Jimmy | |
James Loughner | Re: Property from activeX in a Class on Wed, 25 Feb 2009 18:08:15 -0500 There is a difference between ::XbpActiveXControl:Init(oParent, oOwner, aPos, aSize, aPP, lVisible) and ::HX_PushButton := XbpActiveXControl():new( oParent, oOwner, aPos, aSize, aPP, lVisible) In the first case we are init-ing the super class of HX_Button in the second you are creating a new ActiveX control and assigning a reference to an ivar. Basically you now have two ActiveX controls the first is an uninitiated super class and a initiated second one which is referenced by the ::HX_PushButton ivar. The first way is the correct way your way is the wrong way. Jim AUGE_OHR wrote: > hi, > >> This is not a bug and not a feature. >> Just normal behavior. >> You create an object HX_PushButton as a new member of your class. > > Yes > >> Property BackColor is a member of this new object and not your HX_Button. > > No > >> Why don't you just make something like this. >> >> CLASS HX_Button FROM XbpActiveXControl >> EXPORTED: >> METHOD Init() >> METHOD Create() >> ENDCLASS >> >> METHOD HX_Button:Init(oParent, oOwner, aPos, aSize, aPP, lVisible) >> ::XbpActiveXControl:Init(oParent, oOwner, aPos, aSize, aPP, lVisible) >> RETURN >> >> METHOD HX_Button:Create(oParent, oOwner, aPos, aSize, aPP, lVisible) >> ::XbpActiveXControl:Create(oParent, oOwner, aPos, aSize, aPP, lVisible) >> RETURN > > there is no differens if i have "::HX_Button :=" before both Lines > >> Your class is already derived from XbpActiveXControl. In your example you >> basically create two instances of XbpActiveXControl. > > No, why do you think that ? using ":=" does not meen a new instance. > >> Secondly in your method >> >> HX_Button:_BackColor >> >> I think you meant to put >> xRet := ::HX_PushButton:BackColor >> after the ENDIF, >> now the method doesn't return the value unless you set a new value. > > No every Methode is Read/Write. > > again all works fine but i want to know what is the Difference in : > > ****************************************************************************************** > > oXpb := XbpActiveXControl:New(oParent, oOwner, aPos, aSize, aPP, lVisible) > oXbp:Create() > oXbp:SetProperty("myProperty",xValue) -> this works > > ****************************************************************************************** > > CLASS myClass FROM XbpActiveXControl > ... > > oXpb := myClass:New(oParent, oOwner, aPos, aSize, aPP, lVisible) > oXbp:Create() > > oXbp:SetProperty("myProperty",xValue) -> this dos NOT work !!! > > ****************************************************************************************** > i have to use ASSIGN METHODE to make it work, WHY ? > > greetings by OHR > Jimmy > > | |
AUGE_OHR | Re: Property from activeX in a Class on Thu, 26 Feb 2009 05:11:11 +0100 hi, > There is a difference between > ::XbpActiveXControl:Init(oParent, oOwner, aPos, aSize, aPP, lVisible) > and > ::HX_PushButton := XbpActiveXControl():new( oParent, oOwner, aPos, > aSize, aPP, lVisible) > > In the first case we are init-ing the super class of HX_Button in the > second you are creating a new ActiveX control and assigning a reference > to an ivar. Basically you now have two ActiveX controls the first is an > uninitiated super class and a initiated second one which is referenced > by the ::HX_PushButton ivar. The first way is the correct way your way > is the wrong way. Yes i agree, BUT that is NOT my Code ! *** quote *** CLASS HX_Button FROM XbpActiveXControl EXPORTED: VAR HX_PushButton METHOD Init() METHOD Create() *** see later ENDCLASS METHOD HX_Button:Init(oParent, oOwner, aPos, aSize, aPP, lVisible) ::HX_PushButton := XbpActiveXControl():new( oParent, oOwner, aPos,aSize) ::HX_PushButton:CLSID := ... ::HX_PushButton:License := ... RETURN self METHOD HX_Button:Create(oParent, oOwner, aPos, aSize, aPP, lVisible) ::HX_PushButton:Create() *** see later RETURN self *** eof *** why i do not use "normal" Way ? it is the activeX itself *** quote *** use HX_Class #xtranslate XbpPushButton => HX_Button oDlg := XbpDialog():new( ,,aPos,aSize,aPP ) oDlg:title := "Codejock Button Class" oDlg:titleBar := .T. oDlg:taskList := .T. oDlg:icon := 1 oDlg:create() oXbp := XbpPushButton():new(oDlg:drawingArea , , {20, 10}, {200,80} ) oXbp:caption := "xtpOverlay" oXbp:activate:= {|| msgbox("hallo 1","Hinweis 1") } neu CJ Button oXbp:Icon := "star32.ico" oXbp:create() neu CJ Button, nach create setzen !!! oXbp:Appearance := xtpAppearanceStandard oXbp:Style := xtpButtonNormal oXbp:TextImageRelation := xtpOverlay *** eof *** as you see i use #xtranslate XbpPushButton => HX_Button and have "normal" Xbase++ Code so :caption, :activate and (new) :Icon are before :create() but i have a activeX and no Property or Method are avaiable "before" :create() !!! so the "normal" Way, using a activeX, woud be after :create() like :Appearance while i do NOT want to change my Xbase++ Code i do this : (*** see later) *** quote *** VAR Caption Xbase++ VAR x_Caption Gets or sets the text associated with this control. ASSIGN METHOD _Caption() VAR x_Caption and after :create() IF ::Caption == NIL ::Caption := "" ENDIF after create !!! ASSIGN METHOD "transfer" data ::x_Caption := ::Caption METHOD HX_Button:_Caption(xValue) Gets or sets the text associated with this control. LOCAL xRet IF PCOUNT() > 0 IF VALTYPE(xValue) = "C" STRING ::HX_PushButton:SetProperty("Caption", xValue ) ENDIF ENDIF yes, :GetProperty() must be after ENDIF xRet := ::HX_PushButton:GetProperty("Caption") RETURN xRet this Way i can leave my Xbase++ Code as it is, just include / exclude #xtranslate and you have "dual" Source Code. but back again to my Question and to Class VAR HX_PushButton without ::HX_PushButton, only ::XbpActiveXControl():new(...) was my 1st try, but that crash. >this does NOT work: >oXbp := HX_Button():New(...):create() >oXbp:BackColor := myColor <- CRASH here ... why ??? After include Class VAR ::HX_PushButton := ActiveXControl():new(...) >i have to use >oXbp:HX_PushButton:BackColor := myColor > >or > >VAR myProperty >ASSIGN METHOD _BackColor() VAR BackColor > >oXbp:BackColor := myColor now work it work, so again my Question >i have to use ASSIGN METHODE to make it work, WHY ? greetings by OHR Jimmy | |
James Loughner | Re: Property from activeX in a Class on Wed, 25 Feb 2009 23:44:16 -0500 But your code is wrong. Here is what you need to do, because Activex does not expose its properties before the instance is created you do the active x create in the Init instead of the create. You need a create but it can be just a dummy. ie METHOD HX_Button:Init(oParent, oOwner, aPos, aSize, aPP, lVisible) ::XbpActiveXControl:Init( oParent, oOwner, aPos,aSize) ::XbpActiveXControl:CLSID := ... ::XbpActiveXControl:License := ... ::XbpActiveXControl:Create() RETURN self METHOD HX_Button:Create(oParent, oOwner, aPos, aSize, aPP, lVisible) RETURN self The create is only needed here for the old code and it overloads the ::XbpActiveXControl super class create. What you are doing is creating a second instance not related to the super class instance but are expecting it to work as if it were the super class instance. Problem solved. LOL Jim AUGE_OHR wrote: > hi, > >> There is a difference between >> ::XbpActiveXControl:Init(oParent, oOwner, aPos, aSize, aPP, lVisible) >> and >> ::HX_PushButton := XbpActiveXControl():new( oParent, oOwner, aPos, >> aSize, aPP, lVisible) >> >> In the first case we are init-ing the super class of HX_Button in the >> second you are creating a new ActiveX control and assigning a reference >> to an ivar. Basically you now have two ActiveX controls the first is an >> uninitiated super class and a initiated second one which is referenced >> by the ::HX_PushButton ivar. The first way is the correct way your way >> is the wrong way. > > Yes i agree, BUT that is NOT my Code ! > > *** quote *** > CLASS HX_Button FROM XbpActiveXControl > EXPORTED: > VAR HX_PushButton > METHOD Init() > METHOD Create() > *** see later > ENDCLASS > > METHOD HX_Button:Init(oParent, oOwner, aPos, aSize, aPP, lVisible) > ::HX_PushButton := XbpActiveXControl():new( oParent, oOwner, aPos,aSize) > ::HX_PushButton:CLSID := ... > ::HX_PushButton:License := ... > RETURN self > > METHOD HX_Button:Create(oParent, oOwner, aPos, aSize, aPP, lVisible) > ::HX_PushButton:Create() > *** see later > RETURN self > *** eof *** > > why i do not use "normal" Way ? it is the activeX itself > > *** quote *** > > use HX_Class > > #xtranslate XbpPushButton => HX_Button > > oDlg := XbpDialog():new( ,,aPos,aSize,aPP ) > oDlg:title := "Codejock Button Class" > oDlg:titleBar := .T. > oDlg:taskList := .T. > oDlg:icon := 1 > oDlg:create() > > oXbp := XbpPushButton():new(oDlg:drawingArea , , {20, 10}, {200,80} ) > oXbp:caption := "xtpOverlay" > oXbp:activate:= {|| msgbox("hallo 1","Hinweis 1") } > > neu CJ Button > > oXbp:Icon := "star32.ico" > oXbp:create() > > > neu CJ Button, nach create setzen !!! > > oXbp:Appearance := xtpAppearanceStandard > oXbp:Style := xtpButtonNormal > oXbp:TextImageRelation := xtpOverlay > > *** eof *** > > as you see i use #xtranslate XbpPushButton => HX_Button and have "normal" > Xbase++ Code so :caption, :activate and (new) :Icon are before :create() > > but i have a activeX and no Property or Method are avaiable "before" > :create() !!! so the "normal" Way, using a activeX, woud be after :create() > like :Appearance > > while i do NOT want to change my Xbase++ Code i do this : (*** see later) > *** quote *** > > VAR Caption Xbase++ > VAR x_Caption Gets or sets the text associated with this control. > ASSIGN METHOD _Caption() VAR x_Caption > > and after :create() > > IF ::Caption == NIL > ::Caption := "" > ENDIF > > after create !!! > > ASSIGN METHOD "transfer" data > > ::x_Caption := ::Caption > > > METHOD HX_Button:_Caption(xValue) Gets or sets the text > associated with this control. > LOCAL xRet > IF PCOUNT() > 0 > IF VALTYPE(xValue) = "C" STRING > ::HX_PushButton:SetProperty("Caption", xValue ) > ENDIF > ENDIF > > yes, :GetProperty() must be after ENDIF > > xRet := ::HX_PushButton:GetProperty("Caption") > RETURN xRet > > this Way i can leave my Xbase++ Code as it is, just include / exclude > #xtranslate and you have "dual" Source Code. > > but back again to my Question and to Class VAR HX_PushButton > > without ::HX_PushButton, only ::XbpActiveXControl():new(...) was my > 1st try, but that crash. > >> this does NOT work: >> oXbp := HX_Button():New(...):create() >> oXbp:BackColor := myColor <- CRASH here ... why ??? > > After include Class VAR ::HX_PushButton := ActiveXControl():new(...) > >> i have to use >> oXbp:HX_PushButton:BackColor := myColor >> >> or >> >> VAR myProperty >> ASSIGN METHOD _BackColor() VAR BackColor >> >> oXbp:BackColor := myColor now work > > it work, so again my Question > >> i have to use ASSIGN METHODE to make it work, WHY ? > > greetings by OHR > Jimmy > > > > | |
Sebastiaan | Re: Property from activeX in a Class on Thu, 26 Feb 2009 09:03:37 +0100 James is correct, but to answer you question: > >> Your class is already derived from XbpActiveXControl. In your example you >> basically create two instances of XbpActiveXControl. > > No, why do you think that ? using ":=" does not meen a new instance. > Because your class is derived from XbpActiveXControl, says so in you own code. CLASS HX_Button FROM XbpActiveXControl <--- So your new class basically is an ActiveXControl, no need to create two. And I did not use ":=" in my sample. | |
AUGE_OHR | Re: Property from activeX in a Class on Thu, 26 Feb 2009 14:16:22 +0100 hi, while doing more Property i saw what you both meen and you are right. i did "to much" work while i did ASSIGN METHOD to every Property, but i just want those from XbParts ... with same Name ... so i have to change those Class VAR like ::HX_PushButton to :: and deleted all Methode SetProperty/GetProperty while not need any more ... just use o:myProperty as it shoud. Sorry for my "blackout" greetings by OHR Jimmy | |
AUGE_OHR | Re: Property from activeX in a Class on Thu, 26 Feb 2009 16:18:58 +0100 hi, ... there was a Reason ...it is the Codejock Tabpage and it Tabcontrol. 1st. have to :create() TabControl, no Problem *** qoute *** #xtranslate XbpTabpage => HX_Tabpage Procedure MAIN ... Tabcontrol Manager need as "Parent" oTab := HX_Tab():new(oDlg:drawingArea,,{0,0}, {600,480} ) oTab:create() oTab:PaintManager:Layout := xtpTabLayoutMultiRow oTab:PaintManager:MultiRowJustified := True oTab:PaintManager:MultiRowFixedSelection := True here are the Tabpages FOR i := 1 TO 26 oXbp := XbpTabpage():new(oTab , , {0, 10}, {600,480} ) oXbp:caption := " &"+CHR(i+64)+" " oXbp:Icon := "star32.ico" oXbp:create() NEXT *** eof *** than on that TabControl you have to "insertItem" Tabpages. and now my Problem begin *** quote *** METHOD HX_TabPage:Init(oParent, oOwner, aPos, aSize, aPP, lVisible) ALTD() ::oTabControl := oParent ::XbpActiveXControl:Init(oParent, oOwner, aPos, aSize) ::CLSID := "{DC8335FD-F292-4A6B-9CAF-4E8EBDC5BB55}" * ::HX_Tab := XbpActiveXControl():New(::oTabControl,,{0,0},{0,0}) * ::HX_Tab:CLSID := "{DC8335FD-F292-4A6B-9CAF-4E8EBDC5BB55}" RETURN self METHOD HX_TabPage:Create(oParent, oOwner, aPos, aSize, aPP, lVisible) LOCAL oTab IF ::Icon == NIL ::Icon := "DUMMY.ICO" ENDIF IF ::Caption == NIL ::Caption := "" ENDIF need for SubscribeEvent() ::oTabControl:lfirst := .T. add Tabpage to TabControl oTab := ::oTabControl:insertItem(::nIndex,; ::Caption,; 0,; 1) ::oTabControl:lfirst := .F. ::nIndex++ oTab:enabled := .t. and now create it ::XbpActiveXControl:create(oParent, oOwner, aPos, aSize) -> crash here ALTD() * ::HX_Tab:create() ::autoSize := .t. *** eof *** now it crash, but it work if i use Class VAR ::HX_Tab any Idee ? greetings by OHR Jimmy |