Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Passing parameters by reference to MS Chart
Message
General information
Forum:
Visual FoxPro
Category:
ActiveX controls in VFP
Miscellaneous
Thread ID:
01185464
Message ID:
01185475
Views:
13
It appears that TwipstoChartPart() wouldn't accept parameters by reference in VFP (OLE error code 0x80020005: Type mismatch). W/o that you cannot get there new values back.
On unrelated note, the foolowing your code returns "pixels per Twips", not what your comment says
unLTVX=1440/liPixelsPerInchX
unLTVY=1440/liPixelsPerInchY
>This is something Sergey had helped me with - but he must be taking Sunday off! The big thing I learned so far from Sergey was in regards to passing paramenters to UDFs as references (eg so they would return a value - see @iPart below). The demo below needs to return a parameter passed by reference (i think) to MSChart's TwipstoChartPart method. I would like to know how to determine if this method is "really" exposed to VFP - and if it is, how to make it work. If anyone knows this will not work, or could help me make it work (Windows API functions - maybe), I would be most appreciative - I would be willing to do a few hours of grunge work in exchange. What follows below are my most recent pleas to Sergey.
>****
>Again Sergey my thanks - I was toggeling between setting UDFPARS TO VALUE and then asserting an @iPart. When the CODE breaks from a UDF PARM the environment (i think) has to be cleared.
>
>Any whoo - I got it to bite with an @iPart designation once, and it failed on the Index1 parameter that did not have the '@'. Before that the whole TwipstoChartPart threw an 80020005 (type) error. It was a good feeling (for about 6 seconds) And then as my hacks usually go - without saving a copy with the successful @iPart fire (it was pretty cluttered by that time) I went in and instead of editing ONE thing - I got creative and messed with 2 or three - before I even knew why it worked - and then forgot the [apparent] working hack (I had to mow the lawn today). And then I tried (in vain) to make it happen for 5 hours to no avail. I don't know if the success was because a previous TYPE error had busted the environment (a false success) or because @iPart was .F. or a Zero - or a local paramter. When VB SETs a variable as an integer, is it initialized as a Zero - or as an .F., like VFP? When I (think) had success - the Parameters were local to the mouse move. I moved them to public - but
>left commented LOCAL declaration in mouse move,
>
>Anyway heres a cleaned up test bed. The form chart program (TWIPPER.PRG) and a script to reset the environment (RS.PRG). The caption of the form echos mouse move pixels and mouse move twips to pixel - and on the most right of the caption the iPari is suppose to echo. It works as posted - put iPart is always zero.
>
>Take a look if you can and tell me where I am screwing up - I'll send a bubble/fan dancer to your dwelling for Valentines Day!!!
* Twipper.PRG (terry)
>SET EXACT ON
>DeclareWindowsAPIFunctions()
>PUBLIC myform as Form, unLTVX, unLTVY, iPart As Integer, iseries As Integer,;
>      idatapoint As Integer,ix1 as integer, ix2 as integer, ix3 As Integer,;
>      ix4 As Integer,lUseTwipsToPixels
>STORE 0 TO iPart,iseries,idatapoint,ix1,ix2,ix3,ix4
>GetDisplayMetrics()
>lUseTwipsToPixels=.t. && Use Twips to pixel convertion - else - use pixels (X,Y)
>myform=CREATEOBJECT('frmTwipper')
>myform.show
>
>DEFINE CLASS frmTwipper as form
>height=600
>width=800
>autocenter=.t.
>borderstyle=2
>PROCEDURE release
>this.queryunload
>ENDPROC
>PROCEDURE init
>this.cntChart.width=this.Width
>this.cntChart.Height=this.height
>ENDPROC
>PROCEDURE QueryUnload
>CLEAR EVENTS
>ENDPROC
>
>PROCEDURE resize
>ENDPROC
>ADD OBJECT cntChart as cntChartClass
>visible=.t.
>ENDDEFINE &&frmTwipper
>
>DEFINE CLASS cntChartClass as Container
>top=0
>left=0
>backstyle=1
>backcolor=RGB(255,255,255)
>borderwidth=1
>procedure init
>with this.ocxChart
>.width=thisform.width-2
>.height=thisform.height-2
>.ChartType = 3 && VtChChartType2dLine
>.AllowDithering = .f.
>.AllowSelections = .f.
>.AutoIncrement = .f.
>.AllowDynamicRotation = .f.
>.AllowSeriesSelection = .f.
>.COLUMNCOUNT = 1
>.RowCount = 8
>.Backdrop.Fill.Style= 1 && VtFillStyleBrush
>   with .Backdrop.Fill.Brush.FillColor
>   .red=255
>   .green=255
>   .blue=255
>   ENDWITH &&.Backdrop.Fill.Brush.FillColor
>*!* Populate the DataGrid Object.
>FOR lnCol = 1 TO 1
>   FOR lnRow = 1 TO 8
>   .COLUMN = lnCol
>   .ROW = lnRow
>  .DATA = lnRow * 10
>   NEXT ROW
>NEXT COLUMN
>*!* Use the chart as the backdrop of the legend.
>.ShowLegend = .T.
>.visible=.t.
>ENDWITH &&this.ocxChart
>ENDPROC &&Init
>PROCEDURE resize
>ENDPROC
>ADD OBJECT ocxChart as ocxChartClass
>visible=.t.
>ENDDEFINE &&cntChartClass
>
>define class ocxChartClass as Olecontrol
>OleClass="MSChart20Lib.MSChart.2"
>BorderStyle=1
>top=1
>left=1
>PROCEDURE init
>ENDPROC
>PROCEDURE MouseMove(Button, Shift, X, Y)
>*!*	LOCAL iPart As Integer, iseries As Integer, idatapoint As Integer,;
>*!*	      ix1 as integer, ix2 as integer, ix3 As Integer, ix4 As Integer
>*!*	STORE 0 TO iPart,iseries,idatapoint,ix1,ix2,ix3,ix4
>lnX=IIF(lUseTwipsToPixels,x*unLTVX,x)
>lnY=IIF(lUseTwipsToPixels,y*unLTVY,x)
>*!*	this.object.SelectPart(4, 0, 0, 0, 0)
>this.object.TwipsToChartPart( lnX, lnY, iPart, ix1, ix2, ix3, ix4)
>thisform.caption=PROGRAM(0)+[ - Pixels: ]+TRANSFORM(x)+[, ]+TRANSFORM(y);
>                           +[ - Twips : ]+TRANSFORM(x*unLTVX)+[, ]+TRANSFORM(y*unLTVY);
>                           +[ - TwipsToChartPart : ]+TRANSFORM(iPart)
>ENDPROC
>ENDDEFINE &&ocxChartClass
>
>PROCEDURE DeclareWindowsAPIFunctions()
>declare integer GetActiveWindow in WIN32API
>declare integer GetDC in WIN32API integer iHDC
>declare integer GetDeviceCaps in WIN32API integer iHDC,integer iIndex
>ENDPROC &&R6_PSA_DeclareWindowsAPIFunctions
>
>procedure GetDisplayMetrics()
>local liHwnd,liHDC,liPixelsPerInchX,liPixelsPerInchY
>liHwnd=GetActiveWindow()
>liHDC=GetDC(liHwnd)
>* Pixels per Inch
>liPixelsPerInchX=GetDeviceCaps(liHDC,88)
>liPixelsPerInchY=GetDeviceCaps(liHDC,90)
>* Twips per pixel and store
>unLTVX=1440/liPixelsPerInchX
>unLTVY=1440/liPixelsPerInchY
>ENDPROC &&GetDisplayMetrics()
>* END OF TWIPPER.PRG
And below is the cleaner script
* RS (RS.PRG) ReSet environment
>* When the program breaks on a UDFPARMS error
>* Type DO RS in command window to clear beforw
>* edit and and re-test.
>use
>clear all
>close all
>rele all
>on error
>* END OF RS.PRG
>
>Lucy you - huh - if you have a minute - I would appreciate it - even if I have to learn that the TwipstoChartPart method cannot be properly exposed in VFP. Being Mr. POY (again) is a heavy cross to bare!
>
>Thanks Sergey!
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform